简体   繁体   中英

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

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.

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

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");
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM