首页 > 解决方案 > 从常规 ASP.NET MVC 在 IIS 上使用 .Net 核心捕获 Asp .Net 身份

问题描述

我在 IIS 上部署了一个 ASP.NET Core Web 应用程序,到目前为止一切正常。我有另一个 ASP.NET MVC 应用程序,它使用 ASP.NET Identity 并将 cookie 注入AspNet.ApplicationCookie浏览器,然后将我重定向到我的 .Net Core 应用程序。

我需要做的是在我的 .NET Core 应用程序上获取最初插入到 ASP.NET MVC 上的这个用户,并从我以前的应用程序中获得授权的 asp 身份,这两个应用程序具有相同的域,因此我可以看到存储中的 cookie。

问题是:如何配置 .NET Core 应用程序,使其可以通过以前应用程序的 ASP.NET cookie 进行身份验证,ASP.NET MVC 应用程序对我来说也是一个黑盒。

这是我到目前为止所尝试的:

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddIdentityCookies(); 
app.UseAuthentication();

更新:

这是我添加到我的代码中的内容,但仍然没有得到我以前的身份,我也遇到了一些不熟悉的异常

services.AddAuthentication(option=> {
        new CookieAuthenticationOptions { Cookie = {

           Domain = ".dev.*****.ru",
           Path ="/",
           Name= ".AspNet.ApplicationCookie",
            }
        };
    }).AddIdentityCookies(option=>new CookieAuthenticationOptions
    {
        Cookie = {
           Domain = ".dev.*****.ru",
           Path ="/",
           Name= ".AspNet.ApplicationCookie",
        }
    });

[2019-04-12 11:25:51.903 +03:00 WRN] Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository 使用内存存储库。密钥不会被持久化到存储中。

[2019-04-12 11:25:51.943 +03:00 WRN] Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager 用户配置文件和 HKLM 注册表均不可用。使用临时密钥存储库。应用程序退出时,受保护的数据将不可用。

[2019-04-12 11:25:51.977 +03:00 WRN] Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager 未配置 XML 加密器。密钥“41c89830-2ef1-48f7-afa5-16680973e6f2”可能以未加密的形式保存到存储中。

标签: c#.net.net-coreasp.net-identity

解决方案


推荐阅读