项目作者: synercoder

项目描述 :
Enable ASP.NET Core 2 cookies to read old ASP.NET Forms Authentication cookies
高级语言: C#
项目地址: git://github.com/synercoder/FormsAuthentication.git
创建时间: 2017-09-11T10:26:40Z
项目社区:https://github.com/synercoder/FormsAuthentication

开源协议:MIT License

下载


FormsAuthentication

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

NuGet: NuGet Shield

Usage:

  1. var section = Configuration.GetSection("FormsAuthentication");
  2. var faOptions = new FormsAuthenticationOptions()
  3. {
  4. DecryptionKey = section.GetValue("DecryptionKey"),
  5. ValidationKey = section.GetValue("ValidationKey"),
  6. EncryptionMethod = section.GetValue("EncryptionMethod"),
  7. ValidationMethod = section.GetValue("ValidationMethod"),
  8. };
  9. services
  10. .AddAuthentication(options =>
  11. {
  12. options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  13. options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  14. options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  15. })
  16. .AddCookie(options =>
  17. {
  18. options.Cookie.Name = section.GetValue("CookieName");
  19. options.AccessDeniedPath = "/Login/Upgrade/";
  20. options.LoginPath = "/Login/";
  21. options.ReturnUrlParameter = "returnurl";
  22. options.TicketDataFormat = new FormsAuthenticationDataFormat(
  23. faOptions,
  24. FormsAuthHelper.ConvertCookieToTicket,
  25. FormsAuthHelper.ConvertTicketToCookie
  26. );
  27. });

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.