登陆后,将用户名存入session("username")="$用户名$"在要限制进入的最上面判断session("username")是否为空 if session("username")="" then response.redirect("$登录页面$") response.end end if
谢谢,楼上的是什么语言,我只会JAVA和C#,呵呵
if (session["user"]==null) { 停止执行,并转到登录页面 }
session可靠性不佳.这里有一个方法,楼主可以参考 1\ login.aspx页if validateLogic() then System.Web.Security.FormsAuthentication.SetAuthCookie(用户名.text.trim, boolan值下次是否可以直接登录) System.Web.Security.FormsAuthentication.RedirectFromLoginPage(usr.Text.Trim, chk.Checked) else '用户名或密码错误 end ifpublic function validatelogic() as boolean '自己的验证逻辑,若通过验证,返回true,反之返回false end function 2\web.config中配置 <authentication mode="Forms"> <forms defaultUrl="islogin/default.aspx" loginUrl="login.aspx" name="test" path="/" protection="All" timeout="60"> </forms> </authentication> 3\还是web.config </system.web> <location path="islogin"> <system.web> <authorization> <deny users ="?"/> <allow users ="*"/> </authorization> </system.web> </location>说明将islogin目录下的所有文件保护起来,没有授权的用户不能访问,login.aspx文件根目录下,任意 用户可访问. 然后,你就可以不用每个页来管理session了,也不用写一个page的派生类在其中判断session了.
if session("username")="" then
response.redirect("$登录页面$")
response.end
end if
{
停止执行,并转到登录页面
}
1\
login.aspx页if validateLogic() then
System.Web.Security.FormsAuthentication.SetAuthCookie(用户名.text.trim, boolan值下次是否可以直接登录)
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(usr.Text.Trim, chk.Checked)
else
'用户名或密码错误
end ifpublic function validatelogic() as boolean
'自己的验证逻辑,若通过验证,返回true,反之返回false
end function
2\web.config中配置
<authentication mode="Forms">
<forms defaultUrl="islogin/default.aspx" loginUrl="login.aspx" name="test" path="/" protection="All" timeout="60">
</forms>
</authentication>
3\还是web.config
</system.web> <location path="islogin">
<system.web>
<authorization>
<deny users ="?"/>
<allow users ="*"/>
</authorization>
</system.web>
</location>说明将islogin目录下的所有文件保护起来,没有授权的用户不能访问,login.aspx文件根目录下,任意 用户可访问.
然后,你就可以不用每个页来管理session了,也不用写一个page的派生类在其中判断session了.