Search code examples
asp.netiisrelative-pathvirtual-path

IIS doesn't correctly substitute "~" in VS2012 ASP.NET web site


I have my ASP.NET site generated from Web Forms template in Visual Studio 2012. I have this code in the master page:

<asp:PlaceHolder runat="server">
    <%: Styles.Render("~/Content/themes/base/css", "~/Content/css") %>
    <%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>

When I run my site from VS, all works fine. When I deploy it to the server, css files cannot be loaded because the above code resolves as

<link href="/Content/themes/base/css?v=UM624qf1uFt8dYtiIV9PCmYhsyeewBIwY4Ob0i8OdW81" rel="stylesheet" type="text/css" />
<link href="/Content/css?v=tMLDfv3u-lElLSOX_gsfU7tfsfKPoY_vJBePC7KLa6U1" rel="stylesheet" type="text/css" />
<script src="/bundles/modernizr?v=EuTZa4MRY0ZqCYpBXj_MhJfFJU2QBDf0xGrV_p1fHME1" type="text/javascript"></script>

All the paths are counted from the domain's root, while my site is deployed under a subfolder, like http://MyDomain.com/MySyte/. Obviously, the tilde operator ~ is not handled right. In all other places, like hrefs, it is properly replaced and navigation works fine in deployed site.

Another example. For this code from master page

<asp:ScriptManager runat="server" AjaxFrameworkMode="Explicit">
    <Scripts>
        <asp:ScriptReference Name="MsAjaxBundle" />
        <asp:ScriptReference Name="jquery" />
        ...
    </Scripts>
</asp:ScriptManager>

I have this html output

<script src="/bundles/MsAjaxJs?v=eYkLZimNY09iWQvWpdPDkxCLGwdMBLWkJ4bU5r3y6GU1" type="text/javascript"></script>
<script src="Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>

So the path to jquery is proper and relative, while MsAjaxBundle resulted in some absolute path.

I consider this behavior being a bug. How can I workaround it?

Update:

  • Windows 7 x64
  • IIS 7.5
  • ASP.NET Application Target Framework 4.5
  • IIS Application Pool Framework 4.0

Solution

  • The problem was caused by our proxy server, who actually forwards http://MyDomain/MySite/ to http://InternalDomain:InternalPort/. And for that internal domain application root was actually a site root.