1

I followed the steps described on this Microsoft Document but I haven't been able to get the shared auth to work.

I can see that both webapps generate the auth cookie but they end up overwriting each others so auth only works on whichever app you logged in last.

I have setup both webapps in IIS10. The 4.8 app is a website and the Core 3.1 app is an application inside of it, so they are both running and the same application pool. I set the path on both cookies to be "/" since the core webapp runs on localhost/core.

here is my startup on the ASP.NET 4.8 Web Forms webapp

    public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\test\core");
        //app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
            AuthenticationMode =
                Microsoft.Owin.Security.AuthenticationMode.Active,
            LoginPath = new PathString("/Account/Login.aspx"),
            CookieName = ".AspNet.SharedCookie",
            CookiePath = "/",
            TicketDataFormat = new AspNetTicketDataFormat(
    new DataProtectorShim(
        DataProtectionProvider.Create(dir,
            (builder) => { builder.SetApplicationName("SharedCookieApp"); })
        .CreateProtector(
            "Microsoft.AspNetCore.Authentication.Cookies." +
                "CookieAuthenticationMiddleware",
            "Identity.Application",
            "v2")))
        });

        System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name";
    }
}

and here is the startup for the ASP.NET Core 3.1 app

        public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();

        System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\test\core");

        services.AddDataProtection()
.PersistKeysToFileSystem(dir)
.SetApplicationName("SharedCookieApp");

        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                // Change the options as needed
                options.Cookie.Name = ".AspNet.SharedCookie";
                options.Cookie.Path = "/";
            });
    }
NicoTek
  • 1,127
  • 1
  • 14
  • 34

0 Answers0