0

The problem is:

  1. I have installed UrlRewrite modole on my IIS for "A" website
  2. I have "B" web site (MVC 5.0) which doesn't use 'UrlRewrite' module but get exception when calling UrlHelper.Content("~/blobl/foo/bar"). The exception is because of using UrlRewriter module and using ~ character for function parameter at same time. The exception is:

    System.ArgumentException: Value does not fall within the expected range. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) at System.Web.WebPages.UrlRewriterHelper.WasThisRequestRewritten(HttpContextBase httpContext) at System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) at System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) at System.Web.WebPages.UrlUtil.GenerateClientUrl(HttpContextBase httpContext, String contentPath)

If I uninstall UrlRewrite module, everything will be OK but the "A" website encounters problem. Also, I couldn't find any way to disable this module only for a website.

NOTE: I've checked IIS URL Rewrite module: Url.Content() does not resolve CSS/Image path properly but I don't want to change the source code.

Community
  • 1
  • 1
Mahmoud Moravej
  • 8,705
  • 6
  • 46
  • 65

2 Answers2

0

I suggest you should add your B web site's URLs to ignore list of URL Rewrite.

Add the following in your 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>
Babu Swami
  • 798
  • 3
  • 10
  • Thanks but I don't know all B web sites' urls. Some urls are generated dynamically. Also It adds a UrlRewrite rule for a site that doesn't use this module. I think It would not be a good idea – Mahmoud Moravej Apr 03 '16 at 09:12
0

After a long search I found there is no regular way to enable UrlRewritemodule for a website without affecting other sites.
The simplest way is: removing this module from affected websites by the following line in web.config file:

<configuration>
 <system.webServer>
   <modules>
      <remove name="RewriteModule" />
   </modules>
 </system.webServer>
</configuration>

For more information, check this: https://www.iis.net/configreference/system.webserver/modules

Mahmoud Moravej
  • 8,705
  • 6
  • 46
  • 65