Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

synercoder/FormsAuthentication

Repository files navigation

FormsAuthentication

Enable ASP.NET Core 2 cookies to read old ASP.NET Forms Authentication cookies by implementing a custom ISecureDataFormat.

NuGet: NuGet Shield

Usage:

var section = Configuration.GetSection("FormsAuthentication");
var faOptions = new FormsAuthenticationOptions()
{
 DecryptionKey = section.GetValue<string>("DecryptionKey"),
 ValidationKey = section.GetValue<string>("ValidationKey"),
 EncryptionMethod = section.GetValue<EncryptionMethod>("EncryptionMethod"),
 ValidationMethod = section.GetValue<ValidationMethod>("ValidationMethod"),
};
services
 .AddAuthentication(options =>
 {
 options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
 options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
 options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
 })
 .AddCookie(options =>
 {
 options.Cookie.Name = section.GetValue<string>("CookieName");
 options.AccessDeniedPath = "/Login/Upgrade/";
 options.LoginPath = "/Login/";
 options.ReturnUrlParameter = "returnurl";
 options.TicketDataFormat = new FormsAuthenticationDataFormat<AuthenticationTicket>(
 faOptions,
 FormsAuthHelper.ConvertCookieToTicket,
 FormsAuthHelper.ConvertTicketToCookie
 );
 });

The FormsAuthHelper.ConvertCookieToTicket and FormsAuthHelper.ConvertTicketToCookie helper methods convert an ASP.NET Core AuthenticationTicket to a FormsAuthenticationCookie and vise versa. This class contains the same data as a old ASPNET Cookie.

About

Enable ASP.NET Core 2 cookies to read old ASP.NET Forms Authentication cookies

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /