您现在的位置: smartcar > smartcar特点 > 正文 > 正文

抽丝剥茧浅议ASPNETCookie

  • 来源:本站原创
  • 时间:2021/11/11 10:42:16
前言

可能有人知道Cookie的生成由machineKey有关,machineKey用于决定Cookie生成的算法和密钥,并如果使用多台服务器做负载均衡时,必须指定一致的machineKey用于解密,那么这个过程到底是怎样的呢?

如果需要在.NETCore中使用ASP.NETCookie,本文将提到的内容也将是一些必经之路。

抽丝剥茧,一步一步分析

首先用户通过AccountController-Login进行登录:

//

//POST:/Account/Login

publicasyncTaskActionResultLogin(LoginViewModelmodel,stringreturnUrl)

{

if(!ModelState.IsValid)

{

returnView(model);

}

varresult=awaitSignInManager.PasswordSignInAsync(model.Email,model.Password,model.RememberMe,shouldLockout:false);

switch(result)

{

caseSignInStatus.Success:

returnRedirectToLocal(returnUrl);

//......省略其它代码

}

}

它调用了SignInManager的PasswordSignInAsync方法,该方法代码如下(有删减):

publicvirtualasyncTaskSignInStatusPasswordSignInAsync(stringuserName,stringpassword,boolisPersistent,boolshouldLockout)

{

//...省略其它代码

if(awaitUserManager.CheckPasswordAsync(user,password).WithCurrentCulture())

{

if(!awaitIsTwoFactorEnabled(user))

{

awaitUserManager.ResetAccessFailedCountAsync(user.Id).WithCurrentCulture();

}

returnawaitSignInOrTwoFactor(user,isPersistent).WithCurrentCulture();

}

//...省略其它代码

returnSignInStatus.Failure;

}

想浏览原始代码,可参见官方的Github链接:


本文编辑:佚名
转载请注明出地址  http://www.smartcarf.com/smartcartd/8775.html

热点文章

  • 没有任何图片文章
  • 没有热点文章
推荐文章

  • 没有任何图片文章
  • 没有推荐文章

Copyright © 2012-2020 smartcar版权所有



现在时间: