如何强制用户必须登录后才能访问网站主页?
如何强制用户必须登录后才能访问网站主页?
------最佳解决方案--------------------登录时将用户名存放至SESSION中
然后在主页的Page_Load中检查,如果没有就跳转到登录页面
------其他解决方案--------------------配置文件有权限设置 deny所有用户
------其他解决方案--------------------
FORMS验证中 先将所有匿名用户拒绝,只有登录了的才能方法
那样就不需要每个页面去判断Session
------其他解决方案--------------------如果是asp.net有个global中的session_start方法检查一下。每次进入程序前都要进入那个方法的
------其他解决方案--------------------
拒绝所有匿名用户。
------其他解决方案--------------------if (Session["UserName"].ToString() != "")
{
Response.Redirect("Login.aspx");
}
------其他解决方案--------------------
得先判断不为null吧。
if (Session["UserName"].ToString() != null)
------其他解决方案--------------------
if (Session["UserName"] != null) 应该是对象不为空。
------其他解决方案--------------------在Page_Load时判断是否登录(session 、cookies等)如果没登入跳到登录页面
------其他解决方案--------------------
if (Session["UserName"].ToString() == "")
{
Response.Redirect("Login.aspx");
}
------其他解决方案--------------------Form验证http://msdn.microsoft.com/zh-cn/library/system.web.security.formsauthentication.aspx
------其他解决方案--------------------在Web.config里面设置,具体方法。
设置需要禁止访问的位置:
<location path="function">
<system.web>
<authorization>
<deny users= "? "/>
</authorization>
</system.web>
</location>
允许所有人访问:
<system.web>
<authentication mode="Forms">
<!--设置验证属性-->
<forms name="AuthCookie" loginUrl="Default.aspx"/>
</authentication>
<!--允许所有用户访问-->
<authorization>