2010-06-03 157 views
5

我有很多problems with FormsAuthentication和潜在的工作,我正在考虑将login存储在Session使用会话存储身份验证?

Login: 
Session["Auth.ClientId"] = clientId; 

IsAuthenticated: 
Session["Auth.ClientId"] != null; 

Logout; 
Session["Auth.ClientId"] == null; 

反正我并没有真正使用大部分的花里胡哨的FormsAuthentication。这是一个坏主意吗?

+1

什么是你与窗体身份验证有问题? – 2010-06-03 11:54:37

回答

2

我不会在会话中存储任何有价值的信息。

为了验证我会用:

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) 

无论如何希望这有助于