[英]Url rewrite rule for redirecting to specific page in asp.net webforms
ASP.NET 4.5 Webforms website ASP.NET 4.5 Webforms网站
I have two domains: 我有两个域:
Both pointing to the same site and the default document is set to login.aspx. 两者都指向同一站点,并且默认文档设置为login.aspx。
When someone goes to company.co.ca, I check the Request.ServerVariables["HTTP_HOST"] in the login.aspx.cs and redirect users to company.co.ca/ca/login.aspx 当有人去company.co.ca时,我在login.aspx.cs中检查Request.ServerVariables [“ HTTP_HOST”]并将用户重定向到company.co.ca/ca/login.aspx
I thought I can use the url rewrite and have this rule in my web.config but it doesn't redirect but stays on the main login.aspx. 我以为我可以使用url重写,并在我的web.config中使用此规则,但是它不会重定向,而是保留在主要的login.aspx上。
<rewrite>
<rules>
<rule name="CA HomePage" stopProcessing="true">
<match url="company.co.ca/login.aspx" />
<action type="Redirect" url="company.co.ca/ca/login.aspx" />
</rule>
</rules>
</rewrite>
What am I doing wrong? 我究竟做错了什么? Is there a better way? 有没有更好的办法?
We are planning to add one more domain and so I don't want to do a manual check in login.aspx.cs and redirect and want to find a more general best way. 我们计划再添加一个域,所以我不想手动登录login.aspx.cs并重定向,并希望找到一种更通用的最佳方法。
You check for the host like this with IIS rewrites: 您可以使用IIS重写来检查主机,如下所示:
<rule name="CA HomePage" stopProcessing="true">
<match url="^login.aspx$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^company.com$" />
</conditions>
<action type="Redirect" url="http://company.co.ca/ca/login.aspx" />
</rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.