1

I have 2 ASP.NET applications, one is ASP.NET WebForms on .NET 4.5, and the other in an ASP.NET Core 6 app.

The connection of the user is done on the application in WebForms. When the user is connected, I have to redirect him to the ASP.NET Core application and it must automatically identify the user who has connected.

I use an authentication cookie on the webforms application with FormsAuthenticationTicket.

Is it possible to share this cookie between the 2 applications?

If I ask you this question it's because I'm stuck.

I found some resources about sharing the authentication cookie between ASP.NET MVC and Core applications but I can't find anything for Webforms applications

Thanks for your help !

1 Answer 1

3

You can share the cookie between the asp.net application and asp.net core application. The data protection stack allows sharing Katana cookie authentication and ASP.NET Core cookie authentication tickets.

You need add code like below:

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddAuthentication();
    ...
}

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(@"c:\shared-auth-ticket-keys\"))
});

And in your webform application.

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = "Cookies",
    CookieName = ".AspNetCore.Cookies",
    // CookiePath = "...", (if necessary)
    // ...
    TicketDataFormat = new AspNetTicketDataFormat(
        new DataProtectorShim(
            DataProtectionProvider.Create(new DirectoryInfo(@"c:\shared-auth-ticket-keys\"))
            .CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware",
            "Cookies", "v2")))
});

For more details you can check the link I provided.

And you also can find the refer the webform repo.

Sign up to request clarification or add additional context in comments.

4 Comments

To use AspNetTicketDataFormat I need to install Microsoft.Owin.Security.Interop but the package is deprecated, so NuGet doesn't install it ... Is there a way to install it by force?
@sylvaing I can install it in my local, have you try to use command to install it.
I still have this mistake... The combination of parameters provided to this OData endpoint is no longer supported I don't understand, this package is compatible with versions 4.6.1 and higher. I tried with several versions and I have the same error. Yes, I have tried in command line and different versions of the package. Any idea ? And i created a new project and same error ...
While searching for hours I found the solution ... The packages did not want to install because ... I was using visual studio community 2013. By using visual studio community 2022 everything works perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.