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

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

  1. <legend id='pN2Qd'><style id='pN2Qd'><dir id='pN2Qd'><q id='pN2Qd'></q></dir></style></legend>
      <tfoot id='pN2Qd'></tfoot>
    1. 在两个 ASP.NET Core 应用程序之间共享 Cookie

      时间:2023-07-11

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

        <legend id='LevE8'><style id='LevE8'><dir id='LevE8'><q id='LevE8'></q></dir></style></legend>

              <bdo id='LevE8'></bdo><ul id='LevE8'></ul>
                <tbody id='LevE8'></tbody>
              <tfoot id='LevE8'></tfoot>

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

                本文介绍了在两个 ASP.NET Core 应用程序之间共享 Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在两个单独的 ASP.NET 中使用

                然后我导航到同一子域上的项目#2.但是,项目 #2 无法识别 MySharedCookie 并重新进行身份验证.我得到一个名称相同但值不同的新 cookie:

                我在 ASP.NET Core 中尝试做的事情是否可行?在 ASP.NET Core 中有没有办法可以将项目 #1 的 cookie 与项目 #2 共享?

                解决方案

                这记录在 使用 ASP.NET 和 ASP.NET Core 在应用程序之间共享 cookie.还有一个 Cookie 共享应用示例 可用.

                为了共享 cookie,您在每个应用程序中创建一个 DataProtectionProvider 并在应用程序之间使用一组公共/共享密钥.

                .AddCookie(options =>{options.Cookie.Name = ".SharedCookie";options.Cookie.Domain = "example.com";options.DataProtectionProvider =DataProtectionProvider.Create(new DirectoryInfo("path-tokeys"));});

                I'm using WsFederation in two separate ASP.NET Core projects.

                Each project has the following in Startup.cs

                services.AddAuthentication(sharedOptions =>
                {
                    sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
                })
                .AddWsFederation(options =>
                {
                    options.Wtrealm = Configuration["Wtrealm"];
                    options.MetadataAddress = "http://example.com/metadata.xml";
                    options.SkipUnrecognizedRequests = true;
                    options.RequireHttpsMetadata = false;
                    options.UseTokenLifetime = false;
                })
                .AddCookie(options =>
                {
                    options.Cookie.Name = "MySharedCookie";
                    options.Cookie.Path = "/";
                    options.Cookie.Domain = ".dev.example.com";
                });
                

                I load project #1 in the browser and I get my cookie:

                I then navigate to project #2 on the same sub domain. However, project #2 doesn't recognize MySharedCookie and re-authenticates. I get a new cookie with the same name but a different value:

                Is what I'm trying to do possible in ASP.NET Core? Is there a way in ASP.NET Core I can share project #1's cookie with project #2?

                解决方案

                This is documented at Sharing cookies among apps with ASP.NET and ASP.NET Core. There is also a Cookie Sharing App Sample available.

                In order to share cookies, you create a DataProtectionProvider in each app and using a common/shared set of keys between the apps.

                .AddCookie(options =>
                {
                    options.Cookie.Name = ".SharedCookie";
                    options.Cookie.Domain = "example.com";
                    options.DataProtectionProvider =
                        DataProtectionProvider.Create(new DirectoryInfo("path-tokeys"));
                });
                

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

                上一篇:如何将项目引用添加到 ASP.NET Core 1.0 MVC 项目 下一篇:使用HttpClient分块上传大文件到Controller,IFormFile总是为空

                相关文章

                    <legend id='Pqfu2'><style id='Pqfu2'><dir id='Pqfu2'><q id='Pqfu2'></q></dir></style></legend>
                      <bdo id='Pqfu2'></bdo><ul id='Pqfu2'></ul>

                    <tfoot id='Pqfu2'></tfoot>

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

                  1. <small id='Pqfu2'></small><noframes id='Pqfu2'>