How to redirect a user to another URL from the MVC custom router handler?

I am working with CustomMvcRouterHandler. Based on some logic, I just want to redirect the user to another URL from CustomHandler.

public class CustomMvcRouterHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { if (requestContext.HttpContext.Request.IsAuthenticated) { if (logic is true) { string OrginalUrl = "/Home/AboutUs"; // redirect Url = "/Home/CompanyProfile"; return new MvcHandler(requestContext); } } return new MvcHandler(requestContext); } } 

How to redirect user to "Home / CompanyProfile" from CustomRouterHandler?

+4
source share
1 answer

You can use the underlying ASP.NET Response object to redirect the user to a different URL.

 requestContext.Response.Redirect("/Home/CompanyProfile"); requestContext.Response.End(); 

It will send a redirect response to the browser and complete the processing of the HTTP request.

+1
source

Source: https://habr.com/ru/post/1491957/


All Articles