一.在Web.config中声明:
<authentication mode="Forms">
<forms name="News" path="/" loginUrl="/News/Modules/Users/Login.aspx"
protection="All" timeout="30">
</forms>
</authentication>
二.正常进入页面:
Context.User = user;
FormsAuthentication.SetAuthCookie(tbEmail.Text,true);
其中user是生成的一个用户对象,它拥有userID,userName,EmailAddress等属性。
三.页面间转换:
首先在Global.asax中加入:
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Request.IsAuthenticated == true)
{
Context.User = new Dong.WebModules.Accounts.Business.DongPrincipal(Context.User.Identity.Name);
}
}
然后在另外的页面里取值并进行其它操作:
Dong.WebModules.Accounts.Business.User currentUser =
new Dong.WebModules.Accounts.Business.User((Dong.WebModules.Accounts.Business.DongPrincipal)Context.User);
tbUserName.Text = currentUser.UserName;
tbEmail.Text = currentUser.EmailAddress;
<authentication mode="Forms">
<forms name="News" path="/" loginUrl="/News/Modules/Users/Login.aspx"
protection="All" timeout="30">
</forms>
</authentication>
二.正常进入页面:
Context.User = user;
FormsAuthentication.SetAuthCookie(tbEmail.Text,true);
其中user是生成的一个用户对象,它拥有userID,userName,EmailAddress等属性。
三.页面间转换:
首先在Global.asax中加入:
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Request.IsAuthenticated == true)
{
Context.User = new Dong.WebModules.Accounts.Business.DongPrincipal(Context.User.Identity.Name);
}
}
然后在另外的页面里取值并进行其它操作:
Dong.WebModules.Accounts.Business.User currentUser =
new Dong.WebModules.Accounts.Business.User((Dong.WebModules.Accounts.Business.DongPrincipal)Context.User);
tbUserName.Text = currentUser.UserName;
tbEmail.Text = currentUser.EmailAddress;
博客介绍了在.NET中使用Forms身份验证的方法。首先需在Web.config中声明相关配置,接着正常进入页面时设置用户对象和认证Cookie,最后在页面间转换时,在Global.asax中添加代码,并在其他页面取值操作。
1581

被折叠的 条评论
为什么被折叠?



