Asp.net mvc URL重写下ASP.NET MVC应用程序的重定向不正确
我有IIS中的下一个网站配置:Asp.net mvc URL重写下ASP.NET MVC应用程序的重定向不正确,asp.net-mvc,iis,url-rewriting,arr,Asp.net Mvc,Iis,Url Rewriting,Arr,我有IIS中的下一个网站配置: http://main.domain.com网站(ASP.NET MVC 5应用程序,网站绑定到指定主机,端口80) 默认网站绑定到:80,启用ARR/URL重写模块 DNS设置中指定了通配符绑定*.domain.com 期望的行为是具有http://main.domain.com作为入口点和一组动态用户子域,如http://user1.domain.com,http://user2.domain.com等 现在使用http://main.domain.com
网站(ASP.NET MVC 5应用程序,网站绑定到指定主机,端口80)http://main.domain.com
- 默认网站绑定到:80,启用ARR/URL重写模块
*.domain.com
期望的行为是具有http://main.domain.com
作为入口点和一组动态用户子域,如http://user1.domain.com
,http://user2.domain.com
等
现在使用http://main.domain.com/user/user1
我为main.domain.com
设置了URL重写规则,如下所示:
<rule name="user-redirection" enabled="true" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^([\w\d-]+)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="http://main.domain.com/user/{C:1}/{R:0}" logRewrittenUrl="true" />
</rule>
在这里。。。。浏览器中出现循环重定向错误!可以肯定的是,我已经仔细检查了这种行为:
http://main.domain.com/user/user47
我已正确重定向到http://main.domain.com
http://user47.domain.com/
我收到一个循环重定向错误filterContext.Result = new RedirectResult("http://someotherdomain.com/some/other/path");
还有。。。。我可以看到:
http://main.domain.com/user/user47
我已正确重定向到http://someotherdomain.com/some/other/path
http://user47.domain.com/
我被重定向到http://user47.domain.com/some/other/path
!!!(是的,这不是打字错误,我也仔细检查了这种行为)所以。我需要一个关于如何解决这个问题的想法我试图重现您的案例,您似乎真的遇到了一个重定向循环。因此,我在模式中添加了一个负前瞻组(
(?!main)
),它对我很有效。以下是my web.config的外观:
<rule name="user-redirection" enabled="true" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^(?!main)([\w\d-]+)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="http://main.domain.com/user/{C:1}" logRewrittenUrl="true" />
</rule>
为了调查您的问题,我尝试了:
e、 g.
嗯。。。最后我得到了答案
问题来自安装的应用程序请求路由(ARR)模块,该模块用于对自定义子域进行重写
在服务器代理设置区域中启用代理后,在响应头中反向重写主机选项默认设置为true。禁用此设置可以使重定向在基于子域的重写下正常工作。回答得很好。需要一些时间来检查它是否有用。你知道我为什么会收到http://user47.domain.com/some/other/path
在最后一个指定的情况下作为目标URL?我已经尝试了好几次,它对我很有效。你可以看到这个结果实际上为你做了什么。您还可以尝试使用手动执行此操作。您正在使用哪个版本的asp.net mvc?您是否有其他重定向/重写?您是否有任何代码可以清除响应中的“重定向”标题?谢谢您的帮助。我刚找到答案,并把它贴在下面。
<rule name="user-redirection" enabled="true" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^(?!main)([\w\d-]+)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="http://main.domain.com/user/{C:1}" logRewrittenUrl="true" />
</rule>