Failure reason: From framework4.0 to framework4.5 upgrade process, the original form authentication mode has changed, so no longer support User.Identity.Name original storage mode (based on cookies), to restore this function, I also discovered by accident. Five solutions for reference 1, downgrade processing, reduce your framework to 4.0<compilationDebug="true"targetframework="4.0"/><HttpRuntimetargetframework="4.0"/> 2. Set the current User myself in the Global.asax: (just add this code without downgrading)
Private void Application_AuthenticateRequest(ObjectSender, EventArgse){ HttpCookieCookies= HttpContext. Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (Cookies!= NULL) { FormsAuthenticationTicketTicket= FormsAuthentication.Decrypt(Cookies.Value); HttpContext. Current.User = New System.Security.Principal.GenericPrincipal(New formsidentity ( ), Span class= "KWD" >new string [ 0 ]); < Span class= "pun" >
3, <machinekey validationkey= "..." decryptionkey= "34 ..."
validation= "SHA1" decryption= "AES"
Compatibilitymode= "Framework20sp1"/>4, Sessionauthenticationmodule
Since you ' re in 4.5 and Since you ' re manually issuing the cookie and Since you ' re already intercepting the cookie, then yo U ' re not really using the forms Auth HTTP module at all. I ' d remove that for now. Also, change your module to handle authenticaterequest. See how that works.
Then once you does get it working, I ' d scrap it all in favor of claims and using the sessionauthenticationmodule which are NE W and built into 4.5. It is far simpler and would serialize all of the your roles into a cookies for you.
Http://msdn.microsoft.com/zh-cn/library/system.identitymodel.services.sessionauthenticationmodule (v=vs.110). aspx
5
Make sure, the MachineKey compatibility mode is the same between all applications:
<machinekey compatibilitymode= "Framework20sp1"/>
(The above is the default for 2.0/4.0 applications and is not the default for 4.5 applications and so it would have To BES set explictly in the 4.5 application.)