伪Session这样共享到Service

来源:转载

在显示层用如下代码,把需要存储的值放到线程拥有者里,代码如下

 var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal; var a =new ClaimsIdentity(); a.AddClaim(new Claim("UserId","150")); if (claimsPrincipal != null) claimsPrincipal.AddIdentity(a);

在Service层调用的时候如下:

 var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal; var userId= claimsPrincipal.Claims.FirstOrDefault(c => c.Type == "UserId").Value;

请问这样把Seesion共享到Service可行吗?

分享给朋友:
您可能感兴趣的文章:
随机阅读: