首页 > 代码库 > Thread.CurrentPrincipal & HttpContext.Current.User

Thread.CurrentPrincipal & HttpContext.Current.User

据说要这样写才稳妥

// This principal will flow throughout the request.
VoyagerPrincipal principal = new VoyagerPrincipal(yada, yada, yada);

// Attach the new principal object to the current HttpContext object
HttpContext.Current.User = principal;

// Make sure the Principal is in sync
System.Threading.Thread.CurrentPrincipal = System.Web.HttpContext.Current.User;

Thread.CurrentPrincipal & HttpContext.Current.User