您的位置:首页 > 其它

.NET Framework用户处理机制(FORMS)

2004-11-20 19:28 295 查看
一.在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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: