4

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 ?

svick
  • 236,525
  • 50
  • 385
  • 514
Shubhajyoti Ghosh
  • 1,292
  • 5
  • 27
  • 45

1 Answers1

1

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.

BWiatrowski
  • 591
  • 6
  • 8
  • Not possible. It cause "Redirect loop" error. I am using ASP.NET MVC (Front Controller) not Classic ASP.NET / ASP.NET (Page Controller) – Shubhajyoti Ghosh Jul 18 '13 at 10:19
  • Check /Home/CompanyProfile directly - it should not cause redirect to itself. Raw redirect works in MVC (I used it in version 3 and 4). – BWiatrowski Jul 18 '13 at 10:49
  • I think you miss the line `return new MvcHandler(requestContext);`. and I am using it within Custom Handler. – Shubhajyoti Ghosh Jul 18 '13 at 11:08
  • creates redirect loop – Vojtiik Jul 17 '14 at 11:35
  • 1
    This works: `requestContext.HttpContext.Response.Redirect("/Home/CompanyProfile");` I suspect the redirect error is due to another routing issue. Try redirecting to a static page to test: `requestContext.HttpContext.Response.Redirect("/test.html");` – Shawn McGough Jul 18 '14 at 13:00