问题是:
UrlRewrite
modole
我有“B”网站(MVC 5.0),它不使用“UrlRewrite”模块,但在调用UrlHelper.Content("~/blobl/foo/bar")
时会出现异常。
例外是因为使用UrlRewriter
模块并同时使用~
字符作为函数参数。
例外是:
System.ArgumentException:值不在预期范围内。 在System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo) 在System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) 在System.Web.WebPages.UrlRewriterHelper.WasThisRequestRewritten(HttpContextBase httpContext) 在System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext,String contentPath) 在System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext,String contentPath) 在System.Web.WebPages.UrlUtil.GenerateClientUrl(HttpContextBase httpContext,String contentPath)
如果我卸载UrlRewrite
模块,一切都会正常,但“A”网站遇到问题。另外,我找不到任何方法只为网站禁用此模块。
注意:我已经检查了IIS URL Rewrite module: Url.Content() does not resolve CSS/Image path properly,但我不想更改源代码。
答案 0 :(得分:0)
我建议您添加 B 网站的网址,以忽略网址重写列表。
在web.config中添加以下内容:
<rule name="Ignore URLs" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern="^/blobl/foo/bar\.aspx$" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern="^/blobl/foo/bar/gar\.aspx$" ignoreCase="true" />
</conditions>
</rule>
答案 1 :(得分:0)
经过长时间的搜索,我发现没有常规方法可以为网站启用UrlRewrite
模块,而不会影响其他网站。
最简单的方法是:
通过web.config
文件中的以下行从受影响的网站中删除此模块:
<configuration>
<system.webServer>
<modules>
<remove name="RewriteModule" />
</modules>
</system.webServer>
</configuration>
有关详情,请查看:https://www.iis.net/configreference/system.webserver/modules