This post originated from an RSS feed registered with .NET Buzz
by Paschal.
Original Post: Root and Virtual: path tip
Feed Title: help.net
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/pleloup/Rss.aspx
Feed Description: .Net for mankind !
This can be a nightmare if you develop locally on Windows XP (as everybody should do :-)) under a virtual directory. As I said this morning the ~ to indicate the root for a server side tag doesn't work anymore for this scenario.
Scott suggested a BASE tag but the cons there is about implementing this in every page and changing agin when I deploy the site.
Another solution I just found is to write my images path like this:
~//images/myimage.gif (note the double /) and it works perfectly using a virtual directory or not.
I should also mention the idea submitted by Jeff Gonzalez (thanks for that) about the stylesheets links:
We wrote a config section for our stylesheets that allows them to be configured dynamically via the configuration API. In our PageBase class we use the ~ in our paths.
In our PageBase class we have the following code in our Init method... (forgive me, it is VB.NET)
Dim _StyleSheets As StyleSheetCollection = CType(System.Configuration.ConfigurationSettings.GetConfig("StyleSheetSettings"), CodeMakerX.Foundation.Web.Helpers.StyleSheetSettings).StyleSheets For i As Int32 = 0 To _StyleSheets.Count - 1 Page.Controls.AddAt(0, _StyleSheets(i).Render) Next
The render method for the StyleSheet class returns a LiteralControl built using a stringbuilder...
Inside our Href property get statement, we have the following code to ensure that the path resolves correctly regardless of using virtual directories or having the application reside in the root...
So far we have been able to run all of our web applications on our local machines using vdirs for development, and run them as the root on staging and production.