加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 使用Session来存储身份验证?

发布时间:2020-12-16 03:19:19 所属栏目:asp.Net 来源:网络整理
导读:我有很多 problems with FormsAuthentication和潜在的工作我正在考虑在会话中存储登录? Login:Session["Auth.ClientId"] = clientId;IsAuthenticated:Session["Auth.ClientId"] != null;Logout;Session["Auth.ClientId"] == null; 无论如何,我并没有真正使
我有很多 problems with FormsAuthentication和潜在的工作我正在考虑在会话中存储登录?

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

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

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

无论如何,我并没有真正使用FormsAuthentication的大部分功能.这是一个坏主意吗?

解决方法

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

对于身份验证,我会使用:

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)

无论如何希望这有帮助

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读