Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 22, 2012 02:50 PM by MohSaied
Aug 21, 2012 09:55 AM|LINK
I have an ASP.NET Web Forms site developed under Visual Studio 2012. There is a master page with navigation bar and links to CSS tables. Bot are specified using the application
root operator "~"
<%: Styles.Render("~/Content/themes/base/css", "~/Content/css") %>
<li><a runat="server" href="~/Forms/SelectResults.aspx">Generate Table</a></li>
<li><a runat="server" href="~/BrowseDB.aspx">Browse DB</a></li>
When browsing the page http://localhost/Forms/SelectResults.aspx I see that the "~" is resolved differently for these cases:
<link href="/Content/site.css" rel="stylesheet" type="text/css" />...<li><a href="SelectResults.aspx">Generate Table</a></li><li><a href="../BrowseDB.aspx">Browse DB</a></li>
So path to CSS is absolute and path to other pages is relative. When running on localhost, all works fine. But after deploying my site to the server it has an address http://MyDomain/MySite/, so it is not located in the domain root. And because of absolute paths, no CSS files can be loaded! Navigation works fine, but all the styles are ruined.
Why doesn't "~" operator work in Styles.Render directive? Both code snippets was generated by the standard ASP.NET website template, I didn't modify anything.
Site was developed under Visual Studio 2012, .NET Framework 4.5. My server specifications are:
Aug 22, 2012 02:50 PM|LINK
If I'm following you right, your question is how to get the absolute path from the relative path without using the ~ ?
if this is the case; try using AppDomainAppVirtualPath property for HttpRuntime, which is an exact equivalent to the tilde ~
is the same as