文章分类:
asp.net编程
forms验证方式
说来笑话,做了好多站,竟没用forms验证,这次尝试使用了下,之前一直是windows验证,比较懒,没怎么研究过。
在成功更换了以后,发现不错,可以很方便的解决权限这块了,过几天把代码贴出来。
首先是web.config的配置:
<authentication mode="Forms">
<forms loginUrl="登录页面" defaultUrl="登录成功后跳转页面" name=".ASPXFORMSAUTH"></forms>
</authentication>
<location path="验证路径">
<system.web>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
</system.web>
</location>
接着是登录页面:
判断如果登录信息正确,则
FormsAuthentication.SetAuthCookie(用户名, false, FormsAuthentication.FormsCookiePath);
Response.Redirect(FormsAuthentication.GetRedirectUrl(用户名, false));
最后是退出:
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
还有判断登录页面是否已登录过,如果是则直接跳到登录成功后页面。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(User.Identity.Name))
{
Response.Redirect("跳转页面", true);
}
}
}
好了,代码就这么多,很简答,不知道大家是怎么用forms验证的,呵呵。
来源:本站
添加时间:2009-9-17 22:14:00
点击数:473
文章评论(1)
评论人:魔法辞典
这个好像还挺复杂的啊!不太懂呢!
第
1条
评论时间:2010-2-1 13:45:38
评 论 人:
评论内容:
验 证 码: