How to redirect user to another Url from MVC Custom Router Handler?

3.3k views Asked by At

I am working with CustomMvcRouterHandler, Based on some logic I just want to redirect 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 ?

1

There are 1 answers

5
BWiatrowski On

You can use underlying ASP.NET Response object to redirect user to another URL.

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

It will send redirect response to the browser and end HTTP request processing.