【发布时间】: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