Question

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
Was it helpful?

Solution 2

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.

OTHER TIPS

The tilde is a reference point from the Application Root. It's likely that your MySyte directory is just a folder off of your Web Site, and not configured as an application.

You need to configure your directory as an application in IIS. For IIS 7.x and 8, you would right click your MySyte folder and select Convert To Application and select the appropriate AppPool.

enter image description here

Using the answer feature because I can't comment(not enough privileges), but wanted to thank the op for the syntax to be used in normal asp page.

<asp:PlaceHolder runat="server">
    <%: Styles.Render("~/Content/themes/base/css", "~/Content/css") %>
    <%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top