Sharing cookie authentication from ASP.NET 5+ application to legacy ASP.NET 4.x.

huangapple go评论74阅读模式
英文:

Sharing cookie authentication from ASP.NET 5+ application to legacy ASP.NET 4.x

问题

I searched and found some examples mentioning the sharing of authentication cookies between .NET Framework and .NET Core/5+ applications, but most of citations are of cookies being generated in the older version of .NET being reused in Core, not the opposite that is what I need.

https://stackoverflow.com/questions/54647573/share-cookie-authentication-between-asp-net-core-2-2-and-asp-net-mvc-5-net-fr

https://stackoverflow.com/questions/60031362/share-authentication-cookie-between-net-framework-and-net-core

https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-7.0#share-authentication-cookies-between-aspnet-4x-and-aspnet-core-apps

The closest case was this one.

https://stackoverflow.com/questions/70058135/i-need-my-net-framework-4-7-2-website-to-be-able-to-use-the-authentication-of-m

But the version of reference is seems .NET Core 2.1 and some methods in the answer has been deprecated and I couldn't reproduce it. Also seems the authentication being performed in older application.

How could I setup a web app in ASP.NET 7 with individual accounts authentication and reuse this cookie to authorize other applications (legacy 4.x web apps modules, and also newer applications that'll be implemented)?

英文:

I searched and found some examples mentioning the sharing of authentication cookies between .NET Framework and .NET Core/5+ applications, but most of citations are of cookies being generated in the older version of .NET being reused in Core, not the opposite that is what I need.

https://stackoverflow.com/questions/54647573/share-cookie-authentication-between-asp-net-core-2-2-and-asp-net-mvc-5-net-fr

https://stackoverflow.com/questions/60031362/share-authentication-cookie-between-net-framework-and-net-core

https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-7.0#share-authentication-cookies-between-aspnet-4x-and-aspnet-core-apps

The closest case was this one.

https://stackoverflow.com/questions/70058135/i-need-my-net-framework-4-7-2-website-to-be-able-to-use-the-authentication-of-m

But the version of reference is seems .NET Core 2.1 and some methods in the answer has been deprecated and I couldn't reproduce it. Also seems the authentication being performed in older application.

How could I setup a web app in ASP.NET 7 with individual accounts authentication and reuse this cookie to authorize other applications (legacy 4.x web apps modules, and also newer applications that'll be implemented)?

答案1

得分: 0

The middleware UseCookieAuthentication is obsolete. Configure Cookie authentication with AddAuthentication().AddCookie When you regist the service ,and call app.UseAuthentication() middleware, Here's the document related

You could try as below in your .net core project and follow the case you provided

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie(x =>
    {
        x.DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(.......);
    });
app.UseAuthentication()
英文:

The middleware UseCookieAuthentication is obsolete. Configure Cookie authentication with AddAuthentication().AddCookie When you regist the service ,and call app.UseAuthentication() middleware,Here's the document related

You could try as below in your .net core project and follow the case you provided

    builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(x =>
        {
            
            x.DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(.......);
        }
        );

.....
app.UseAuthentication()
......

huangapple
  • 本文由 发表于 2023年5月17日 11:36:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268394.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定