Home > database >  how to redirect to login page in dotnet core, if the user enters login.aspx in the url
how to redirect to login page in dotnet core, if the user enters login.aspx in the url

Time:07-07

I am working on the migration of web forms to dotnet core. i have a login page as login.cshtml and this is set as the default page for the application, I need to redirect to the login page when the user enters login.aspx in the login URL. currently, it is showing as page not found, but I need it to redirect to the login page.

CodePudding user response:

Can't you do this with forms-based authentication? Form Based Authentication

CodePudding user response:

this is solved using IHttpRequestFeature below is the code i have done: _httpContextAccessor is initialized in the constructor.

var rf = _httpContextAccessor.HttpContext.Features.Get<IHttpRequestFeature>();
            var rt = requestFeature.RawTarget;
            if (rt.Contains("/login.aspx", System.StringComparison.OrdinalIgnoreCase))
            {
                return Redirect("login");
            }
  • Related