Search code examples
c#asp.net-corehttp-redirectasp.net-core-identity

Hyphen in the host name is getting lost on redirect


I use AuthenticationProperties to expire the user session in based on the ExpiresUtc value. The session times out fine but the URL loses the hyphens on the host name when redirect happens.

Current page when session times-out redirect happens from:

for eg: https://web-beta-test.chocolate.com/Search to https://webbetatest.chocolate.com/?ReturnUrl=%2FSearch

The hyphen is lost and therefore the server cannot find the page. localhost works fine on redirect to get me to the login page, because there are no hyphens involved.

What do I fix? Tips please

 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;

Solution

  • For anyone who comes across this situation with lost hyphens - there is nothing wrong with the Authentication - the issue was with the load-balancer. It had to be corrected to allow the hyphens when the redirect occurs.