在显示层用如下代码,把需要存储的值放到线程拥有者里,代码如下
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可行吗?