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 "~"
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:
mikhail.matr...
0 Points
6 Posts
Why application root “~” resolves to site root “/” in ASP.NET?
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 "~"
When browsing the page http://localhost/Forms/SelectResults.aspx I see that the "~" is resolved differently for these cases:
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:
MohSaied
Member
13 Points
8 Posts
Re: Why application root “~” resolves to site root “/” in ASP.NET?
Aug 22, 2012 02:50 PM|LINK
Hi,
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 ~
ie:
HttpRuntime.AppDomainAppVirtualPath
is the same as
~