簡體   English   中英

在ASP.NET Core中的應用程序和子應用程序之間共享Cookie

[英]Share Cookie between application and sub application in ASP.NET Core

我正在尋找一種在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);

很難找到有關此特定方案的信息。 任何幫助將不勝感激。

我認為此Cookie已使用新的數據保護系統加密。

您的根應用程序將使用其私鑰對cookie進行加密。 您的子應用程序當前無權訪問此私鑰,並且將無法解密此Cookie。

為了使您的子應用程序能夠解密cookie,您將需要設置一個共享密鑰存儲提供程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM