【发布时间】:2021-07-31 07:17:35
【问题描述】:
我使用 AuthenticationProperties 根据 ExpiresUtc 值使用户会话到期。会话超时正常,但发生重定向时 URL 会丢失主机名上的连字符。
会话超时重定向发生时的当前页面:
例如: https://web-beta-test.chocolate.com/Search 到 https://webbetatest.chocolate.com/?ReturnUrl=%2FSearch
连字符丢失,因此服务器无法找到该页面。 localhost 可以很好地重定向到登录页面,因为不涉及连字符。
我要解决什么问题?请指教
try
{
var principal = await CreatePrincipal(userTicket.LoginName, userTicket, null);
var context = _accessor.HttpContext;
await context.SignInAsync(principal, GetAuthProperties());
context.User = principal;
return true;
}
private AuthenticationProperties GetAuthProperties()
{
var authProperties = new AuthenticationProperties
{
AllowRefresh = true,
// Refreshing the authentication session should be allowed.
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(SessionTime),
// The time at which the authentication ticket expires. A
// value set here overrides the ExpireTimeSpan option of
// CookieAuthenticationOptions set with AddCookie.
IsPersistent = false,
// Whether the authentication session is persisted across
// multiple requests. When used with cookies, controls
// whether the cookie's lifetime is absolute (matching the
// lifetime of the authentication ticket) or session-based.
IssuedUtc = DateTime.Now
// The time at which the authentication ticket was issued.
};
var principal = await CreatePrincipal(userTicket.LoginName, userTicket, null);
var context = _accessor.HttpContext;
await context.SignInAsync(principal, GetAuthProperties()); context.User = principal;
【问题讨论】:
-
执行重定向的代码在哪里。
-
用代码更新了问题。我知道一旦时间到期(在 ExpiresUtc 中设置),用户会自动重定向到根页面 - 我将用户重定向到登录页面。如果我错了,请纠正我。
-
我不知道。您使用的是核心/非核心、asp.net-identity、网页、剃须刀页面吗?看起来可能是 Core-Identity。
-
你是正确的 - .net 核心身份使用户会话过期
-
您使用的是 CookieAuthenticationOptions 还是 IdentityOptions? (Core 是什么版本?1.x 2.x 还是 3.x)?
标签: c# asp.net-core redirect asp.net-core-identity