【问题标题】:Hyphen in the host name is getting lost on redirect主机名中的连字符在重定向时丢失
【发布时间】:2021-07-31 07:17:35
【问题描述】:

我使用 AuthenticationProperties 根据 ExpiresUtc 值使用户会话到期。会话超时正常,但发生重定向时 URL 会丢失主机名上的连字符。

会话超时重定向发生时的当前页面:

例如: https://web-beta-test.chocolate.com/Searchhttps://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


【解决方案1】:

对于遇到这种连字符丢失情况的任何人 - 身份验证没有任何问题 - 问题出在负载平衡器上。发生重定向时必须更正它以允许使用连字符。

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多