我正在使用我自己的身份验证方案,非基于cookie。我希望能够使用用户名和我通常在FormsAuthentication Cookie中设置的其他数据手动设置Controller.User.Identity
。目前,用户身份由FormsAuthentication设置(我不知道如何,它只是从加密的cookie中读取它)。 FormsAuthentication是如何做到的?我该怎么做?
答案 0 :(得分:1)
System.Web.HttpContent.Current.User = new GenericPrincipal(
new GenericIdentity("username", "CUSTOM"),
new string[]());
System.Threading.Thread.CurrentPrincipal = System.Web.HttpContent.Current.User;