【问题标题】:Using Session to store authentication?使用 Session 存储身份验证?
【发布时间】:2010-06-03 11:38:46
【问题描述】:
我有很多problems with FormsAuthentication,作为潜在的工作,我正在考虑将login 存储在Session 中?
Login:
Session["Auth.ClientId"] = clientId;
IsAuthenticated:
Session["Auth.ClientId"] != null;
Logout;
Session["Auth.ClientId"] == null;
无论如何,我并没有真正使用FormsAuthentication 的大部分花里胡哨。这是一个坏主意吗?
【问题讨论】:
标签:
asp.net
forms-authentication
【解决方案1】:
我不会在会话中存储任何有价值的信息。
对于身份验证,我会使用:
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
// Then u use
// this.User.Identity.Name as my membership_id so i could call this everywhere
}else
{
//Redirect to Login
//gettting my LoginPageAddress
Response.Redirect(ConfigurationSettings.AppSettings["LoginPage"]);
}
登录是这样的:
FormsAuthentication.SetAuthCookie(membership_ID, false)
无论如何希望这会有所帮助