【问题标题】:Share Cookie between application and sub application in ASP.NET Core在 ASP.NET Core 中的应用程序和子应用程序之间共享 Cookie
【发布时间】:2017-04-28 06:15:25
【问题描述】:

我正在寻找一种在 ASP.NET Core 中的根应用程序和子应用程序(配置为应用程序的虚拟目录)之间共享登录屏幕的方法。子应用程序的 LoginPath 将指向根登录页面(returnUrl 然后将指向子应用程序)。基本上,我需要子应用程序来识别根应用程序设置的凭据。我正在使用 cookie 身份验证。

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookie",
    LoginPath = new PathString("./signin/"),
    AccessDeniedPath = new PathString("/unauthorized/"),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});

这是我发布凭据的代码。

var issuer = SettingBusiness.GetSettingValueAsString("MembersSiteUrl");
var claims = new List<Claim> {new Claim(ClaimTypes.Name, user.UserId.ToString(), ClaimValueTypes.Integer32, issuer)};
var userIdentity = new ClaimsIdentity("MembersUser");
userIdentity.AddClaims(claims);
var userPrincipal = new ClaimsPrincipal(userIdentity);
var authenticationProperties = new AuthenticationProperties
{`enter code here`
    ExpiresUtc = DateTime.UtcNow.AddMinutes(60),
    IsPersistent = false,
    AllowRefresh = true
};
await HttpContext.Authentication.SignInAsync("Cookie", userPrincipal, authenticationProperties);

很难找到有关此特定场景的信息。任何帮助将不胜感激。

【问题讨论】:

    标签: c# asp.net-core asp.net-core-mvc .net-core


    【解决方案1】:

    我假设这个 cookie 是用新的data protection system 加密的。

    您的根应用程序将使用其私钥加密 cookie。您的子应用程序当前无权访问此私钥,也无法解密此 cookie。

    为了让您的子应用能够解密 cookie,您需要设置一个共享的key storage provider

    【讨论】:

      猜你喜欢
      • 2018-12-20
      • 2018-08-25
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多