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

孤者浪人 提交于 2019-12-12 11:33:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!