【问题标题】: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)

无论如何希望这会有所帮助

【讨论】:

    【解决方案2】:

    我不认为这是一个坏主意,我已经看到很多网站使用会话和数据库来存储身份验证数据,但是还有其他方法可以绕过不使用表单身份验证表但仍然能够使用诸如角色之类的东西。

    How do I create a custom membership provider for ASP.NET MVC 2?

    有很好的例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 2017-03-01
      • 2019-03-12
      • 2011-03-07
      • 2020-01-03
      • 2018-10-21
      相关资源
      最近更新 更多