希望将asp.net MVC中的所有请求从给定的域重定向到特定的视图页面

时间:2023-01-16 15:52:57

I want to have on my existing IIS web site an additional host header that will always redirect url's that come in with that domain to a specific mvc razor view page. I've updated my global.asax as follows which kind of works but feels awkward and changes the URL to show the new URL which I don't want.

我希望在我现有的IIS web站点上有一个附加的主机头,它总是将带有该域的url重定向到特定的mvc razor视图页面。我已经更新了我的全球。asax如下所示,这是一种工作方式,但感觉很尴尬,并更改了URL以显示我不想要的新URL。

That is, I want all reqeusts that come in on the domain foo.org to redirect to the view /giving/svccgiving and for the users browser to continue to say foo.org

也就是说,我希望所有访问域foo。org的reqeusts可以重定向到view /giving/svccgiving /svccgiving,并让用户浏览器继续输入foo。org

Here is the code I tried that partially works. any better suggestions?

这是我尝试过的部分有效的代码。什么更好的建议吗?

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (Request.Url.AbsoluteUri.ToLower().Contains("foo.org") &&
        !Request.Url.AbsoluteUri.ToLower().Contains("giving/svccgiving"))
    {
        Response.Redirect("~/Giving/SVCCGiving");
    }
}

1 个解决方案

#1


1  

The following works fine for me,

以下对我来说很好,

this.Response.Redirect("~/Giving/SVCCGiving", true);

this.Response。重定向(“~ / / SVCCGiving”,真正的);

because, the response end is true so further processing of the request does not take place

因为,响应端是正确的,所以请求的进一步处理不会发生。

#1


1  

The following works fine for me,

以下对我来说很好,

this.Response.Redirect("~/Giving/SVCCGiving", true);

this.Response。重定向(“~ / / SVCCGiving”,真正的);

because, the response end is true so further processing of the request does not take place

因为,响应端是正确的,所以请求的进一步处理不会发生。