问题
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:
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.
来源:https://stackoverflow.com/questions/17708202/how-to-redirect-user-to-another-url-from-mvc-custom-router-handler