Kombinieren https://github.com/GrabYourPitchforks/aspnet5-samples/tree/dev/CookieSharing und Sharing authentication cookie among Asp.Net Core 1 (MVC6) and MVC 5 applications Ich war in der Lage, eine funktionierende Lösung zu finden. Ich habe keine Ahnung, ob dies die „richtige“ Art und Weise ist es, aber es funktioniert, so geht es hier:
das nuget-Paket Microsoft.Owin.Security.Interop 1.0.0-rc2-final
in beiden Anwendungen verwenden.
Erstellen Sie eine TicketDataFormat
mit DataProtectionProvider
Angabe der gleichen Speicherort auf der Festplatte für die Verschlüsselungsschlüssel, sowie den gleichen Zweck.
Konfigurieren Sie die Cookie-Authentifizierung in beiden Anwendungen. Geben Sie den gleichen CookieName
und TicketDataFormat
:
.NET 4.5.1 im Configure Methode Startup.cs
:
var authenticationType = "Cookies";
var cookieName = "myCookieName";
var cookieEncryptionKeyPath= "C:/mypath";
var dataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(cookieEncryptionKeyPath));
var dataProtector = dataProtectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", authenticationType, "v2");
var ticketDataFormat = new AspNetTicketDataFormat(new DataProtectorShim(dataProtector));
app.SetDefaultSignInAsAuthenticationType(authenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = authenticationType,
CookieName = cookieName,
TicketDataFormat = ticketDataFormat
});
.NET CORE RC2 in dem Configure-Methode von Startup.cs
:
var authenticationType = "Cookies";
var cookieName = "myCookieName";
var cookieEncryptionKeyPath= "C:/mypath";
var protectionProvider = DataProtectionProvider.Create(new DirectoryInfo(cookieEncryptionKeyPath));
var dataProtector = protectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", authenticationType, "v2");
var ticketFormat = new TicketDataFormat(dataProtector);
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
CookieName = options.CookieName,
CookieDomain = options.CookieDomain,
TicketDataFormat = ticketFormat
});
Ich hoffe, du kannst das herausfinden. Ich bin im gleichen Boot und muss Cookies von RC2 an 4.6.1 weitergeben. – Matthew