My world is virtual

OK I figured out yesterday how to make my URL rewriting working. Strangely, I just had to keep my original Form tag to have everything working properly.

Now another puzzling question. As many develoipers I write my code locally and I mange a lot of different web applications.
So my world is made of virtual directory.

Of course, this is great only locally, because when I deploy to my servers, everything back to the root for most of the stuff.

I know everything about relative and absolute paths, root (~). The question is how to code one good way my paths to be sure that nothing break when I move from my virtual world to my real world ?

By the way sadly some tags cannot be transformed as server side tags. An important one is the <Link tag to embed a stylesheet.

Other curious thing: if you use URL rewriting, the ~ root trick don't work anymore and it's easy to understand why :-)

So what are the solutions to make my world an happy one ?

 

6 Comments

  • Hi Scott. Well I know Base href but it's not really flexible, I have to declare this in every page.

    I am looking for something which let me with a universal solution, whatever if the site is in a virtual directory or at the root.

  • By the way at VS 2005 demo, I could see the new web server feature. It seems that VS create a website for each application. If it's true, this is a cool solution to have multiple websites on my development PC

  • 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.



    The config file xml looks like....



    &lt;StyleSheetSettings&gt;

    &lt;StyleSheet Name=&quot;DefaultPage&quot; Href=&quot;~/Lib/Css/DefaultPage.css&quot; Media=&quot;Screen&quot;/&gt;

    &lt;/StyleSheetSettings&gt;



    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(&quot;StyleSheetSettings&quot;), 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...



    _sb = new StringBuilder();



    _sb.Append(Environment.NewLine);

    _sb.Append(&quot;&lt;link media=\&quot;\&quot;&quot;).Append(Media).Append(&quot;\&quot;\&quot; &quot;);

    _sb.Append(&quot;href=\&quot;\&quot;).Append(_StylePath).Append(Href).Append(\&quot;\&quot; &quot;);

    _sb.Append(&quot;type=\&quot;text/css\&quot; rel=\&quot;stylesheet\&quot;&gt;&quot;);

    _sb.Append(Environment.NewLine);



    return new LiteralControl(_sb.ToString());



    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...



    if( _Href.IndexOf(&quot;~&quot;) == 0 )

    {

    if (System.Web.HttpContext.Current.Request.ApplicationPath == &quot;/&quot; )

    {

    _Href = _Href.Replace(&quot;~&quot;, &quot;&quot;);

    }

    else

    {

    _Href = _Href.Replace(&quot;~&quot;, System.Web.HttpContext.Current.Request.ApplicationPath);

    }

    }



    return _Href



    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.



    Hope this helps.

  • Use windows 2003 server configured as a workstation to host multiple sites.



    I then configure entries in the hosts file to point to the localhost



    127.0.0.1 project1

    127.0.01 project2



    Works like a charm !

  • Windows 2003 ? Not sure I would like to do that to my laptop :-) Too much hassle.

    But yes I reckon it's a solution. But I can't justify spending a day to rebuild my machine !

  • Well if you check out the asp.net forums (v2), they basically have a class that's contains all the URL's (which are accessed from a config file).



    I've not really looked into.



    Yes VS 2005 has it's own web server. My god it's really fast as well (May build). What I mean is you press F5 and bam your site is running in debug. Recommended.

Comments have been disabled for this content.