<bdo id='4za4c'></bdo><ul id='4za4c'></ul>

        <i id='4za4c'><tr id='4za4c'><dt id='4za4c'><q id='4za4c'><span id='4za4c'><b id='4za4c'><form id='4za4c'><ins id='4za4c'></ins><ul id='4za4c'></ul><sub id='4za4c'></sub></form><legend id='4za4c'></legend><bdo id='4za4c'><pre id='4za4c'><center id='4za4c'></center></pre></bdo></b><th id='4za4c'></th></span></q></dt></tr></i><div id='4za4c'><tfoot id='4za4c'></tfoot><dl id='4za4c'><fieldset id='4za4c'></fieldset></dl></div>
        <legend id='4za4c'><style id='4za4c'><dir id='4za4c'><q id='4za4c'></q></dir></style></legend>
      1. <tfoot id='4za4c'></tfoot>

        <small id='4za4c'></small><noframes id='4za4c'>

      2. ASP.NET Core RC2 和 .NET 4.5.1 应用程序之间的共享 cookie 身份验证

        Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps(ASP.NET Core RC2 和 .NET 4.5.1 应用程序之间的共享 cookie 身份验证)
        <legend id='iArnJ'><style id='iArnJ'><dir id='iArnJ'><q id='iArnJ'></q></dir></style></legend>

          • <bdo id='iArnJ'></bdo><ul id='iArnJ'></ul>
              <tbody id='iArnJ'></tbody>
            <tfoot id='iArnJ'></tfoot>

            <small id='iArnJ'></small><noframes id='iArnJ'>

                  <i id='iArnJ'><tr id='iArnJ'><dt id='iArnJ'><q id='iArnJ'><span id='iArnJ'><b id='iArnJ'><form id='iArnJ'><ins id='iArnJ'></ins><ul id='iArnJ'></ul><sub id='iArnJ'></sub></form><legend id='iArnJ'></legend><bdo id='iArnJ'><pre id='iArnJ'><center id='iArnJ'></center></pre></bdo></b><th id='iArnJ'></th></span></q></dt></tr></i><div id='iArnJ'><tfoot id='iArnJ'></tfoot><dl id='iArnJ'><fieldset id='iArnJ'></fieldset></dl></div>
                  本文介绍了ASP.NET Core RC2 和 .NET 4.5.1 应用程序之间的共享 cookie 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们有两个运行共享 cookie 身份验证的 .NET 应用程序.一个是 ASP.NET Core RC1 应用,另一个是经典的 .NET 4.5.1 应用.

                  We have two .NET-apps running shared cookie authentication. One is an ASP.NET Core RC1 app, and the other is a classic .NET 4.5.1 app.

                  目前这是在 Startup.csConfiguration 方法中使用过时的 Microsoft.Owin.Security.Cookies.Interop 设置的:

                  This is currently set up using the outdated Microsoft.Owin.Security.Cookies.Interop in the Configuration method of Startup.cs:

                  这很好用,但不支持 RC2 的方法.

                  This works fine, but is no supported method for RC2.

                  我们如何才能使用 RC2 的共享 cookie 身份验证?

                  How can we get going with shared cookie authentication for RC2?

                  推荐答案

                  结合https://github.com/GrabYourPitchforks/aspnet5-samples/tree/dev/CookieSharing 和 在 Asp.Net Core 1 (MVC6) 和 MVC 5 应用程序之间共享身份验证 cookie 我想出了一个可行的解决方案.我不知道这是否是正确"的方法,但它有效,所以就这样吧:

                  Combining https://github.com/GrabYourPitchforks/aspnet5-samples/tree/dev/CookieSharing and Sharing authentication cookie among Asp.Net Core 1 (MVC6) and MVC 5 applications I was able to come up with a working solution. I have no idea if this is the "correct" way to to it, but it works, so here it goes:

                  1. 在两个应用程序中使用 nuget-package Microsoft.Owin.Security.Interop 1.0.0-rc2-final.

                  使用 DataProtectionProvider 创建一个 TicketDataFormat,指定加密密钥在磁盘上的相同位置以及相同的用途.

                  Create a TicketDataFormat using DataProtectionProvider specifying the same location on disk for the encryption keys, as well as the same purpose.

                  在两个应用程序中以自己的方式配置 cookie 身份验证.指定相同的CookieNameTicketDataFormat:

                  Configure cookie authentication the owin way in both of the applications. Specify the same CookieName and TicketDataFormat:

                  .NET 4.5.1,在Startup.cs的Configure方法中:

                  .NET 4.5.1, in the Configure method of Startup.cs:

                  var authenticationType = "Cookies";
                  var cookieName = "myCookieName";
                  var cookieEncryptionKeyPath= "C:/mypath";
                  
                  var dataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(cookieEncryptionKeyPath));
                  var dataProtector = dataProtectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", authenticationType, "v2");
                  var ticketDataFormat = new AspNetTicketDataFormat(new DataProtectorShim(dataProtector));
                  
                  app.SetDefaultSignInAsAuthenticationType(authenticationType);
                  app.UseCookieAuthentication(new CookieAuthenticationOptions
                          {
                              AuthenticationType = authenticationType,
                              CookieName = cookieName,
                              TicketDataFormat = ticketDataFormat
                          });
                  

                  .NET CORE RC2 在Startup.cs的Configure方法中:

                  .NET CORE RC2 in the Configure method of Startup.cs:

                  var authenticationType = "Cookies";
                  var cookieName = "myCookieName";
                  var cookieEncryptionKeyPath= "C:/mypath";
                  
                  var protectionProvider = DataProtectionProvider.Create(new DirectoryInfo(cookieEncryptionKeyPath));
                  var dataProtector = protectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", authenticationType, "v2");
                  var ticketFormat = new TicketDataFormat(dataProtector);
                  
                  
                  app.UseCookieAuthentication(
                                  new CookieAuthenticationOptions
                                  {
                                      CookieName = options.CookieName,
                                      CookieDomain = options.CookieDomain,
                                      TicketDataFormat = ticketFormat
                                  });
                  

                  这篇关于ASP.NET Core RC2 和 .NET 4.5.1 应用程序之间的共享 cookie 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                  <small id='NYR6f'></small><noframes id='NYR6f'>

                  • <tfoot id='NYR6f'></tfoot><legend id='NYR6f'><style id='NYR6f'><dir id='NYR6f'><q id='NYR6f'></q></dir></style></legend>
                      <tbody id='NYR6f'></tbody>

                            <bdo id='NYR6f'></bdo><ul id='NYR6f'></ul>

                            <i id='NYR6f'><tr id='NYR6f'><dt id='NYR6f'><q id='NYR6f'><span id='NYR6f'><b id='NYR6f'><form id='NYR6f'><ins id='NYR6f'></ins><ul id='NYR6f'></ul><sub id='NYR6f'></sub></form><legend id='NYR6f'></legend><bdo id='NYR6f'><pre id='NYR6f'><center id='NYR6f'></center></pre></bdo></b><th id='NYR6f'></th></span></q></dt></tr></i><div id='NYR6f'><tfoot id='NYR6f'></tfoot><dl id='NYR6f'><fieldset id='NYR6f'></fieldset></dl></div>