C#学习教程:ASP.NETCoreRC2和.NET4.5.1应用程序之间的共享cookie身份验证验证。一个是ASP.NETCoreRC1应用程序,另一个是经典的.NET4.5.1应用程序。这是在Startup.cs的Configuration方法中使用过时的Microsoft.Owin.Security.Cookies.InteropConfiguration:这工作正常,但不支持RC2方法。我们如何使用RC2的共享cookie身份验证?结合https://github.com/GrabYourPitchforks/aspnet5-samples/tree/dev/CookieSharing并在Asp.NetCore1(MVC6)和MVC5应用程序之间共享身份验证cookie,我能够想出一个可行的解决方案。我不知道这是否是“正确”的方法,但它有效,所以这里是:在两个应用程序中使用nuget-packageMicrosoft.Owin.Security.Interop1.0.0-rc2-final。使用DataProtectionProvider创建TicketDataFormat,为加密密钥指定磁盘上的相同位置和相同的目的。在两个应用程序中以owin方式配置cookie身份验证。指定相同的CookieName和TicketDataFormat:.NET4.5.1,在Startup.cs的Configure方法中:varauthenticationType="Cookies";varcookieName="myCookieName";varcookieEncryptionKeyPath="C:/mypath";vardataProtectionProvider=DataProtectionProvider.Create(newDirectoryInfo(cookieEncryptionKeyPath));vardataProtector=dataProtectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware",authenticationType,"v2");varticketDataFormat=newAspNetTicketDataFormat(newDataProtectorShim);dataProtect.SetDefaultSignInAsAuthenticationType(authenticationType);app.UseCookieAuthentication(newCookieAuthenticationOptions{AuthenticationType=authenticationType,CookieName=cookieName,TicketDataFormat=ticketDataFormat});Startup.cs的Configure方法中的.NETCORERC2:以上是C#学习教程:ASP.NETCoreRC2与.NET4.5.1应用程序之间的共享cookie认证所有内容分享,如果对你和你有用需要了解更多C#学习教程,希望大家多多关注——varauthenticationType="库克ies";varcookieName="myCookieName";varcookieEncryptionKeyPath="C:/mypath";varprotectionProvider=DataProtectionProvider.Create(newDirectoryInfo(cookieEncryptionKeyPath));vardataProtector=protectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware",authenticationType,"v2");varticketFormat=newTicketDataFormat(dataProtector);app.UseCookieAuthentication(newCookieAuthenticationOptions{CookieName=options.CookieName,CookieDomain=options.CookieDomain,TicketDataFormat=ticketFormat});代表立场,如涉及侵权,请点击维权联系管理员删除,如需转载请注明出处:
