Re: How to remove virtual path from root url of dev web server?
- From: "Steve Franks" <please@xxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Sep 2005 15:23:24 -0400
Its my understanding that the "~" special character is only interpreted by
server side controls. So I thought I'd try something like:
<table border=0 width=100 background="~/images/something.gif" runat=server>
To see if somehow magically ASP.NET would update the background url to
expand the ~ character, but this was wishful thinking I guess :)
Can you see the challenge I am facing here?
There are some parts of HTML such as the BACKGROUND attribute of a table
cell, and URLs used in style sheets, which cannot be done using server side
controls where the option for automatic conversion from "~" to the real path
would be performed. This leaves me scratching my head as to how to address
it.
As a specific example, assume you have a /images directory that contains a
graphic you want to use for a table background.
If you do this:
<table border=0 width=100 background="/images/something.gif">
then this is wrong when developing locally because of VS.NET and the
application name. So on my local dev machine the real path to the image is
really "/mysite/images/something.gif" yet on production its just
"/images/something.gif".
So I cannot hard code the URL either way, because it will work on dev but
not production, or vice-versa.
And, I cannot do this with the ~ character:
<table border=0 width=100 background="~/images/something.gif" runat=server>
because the table tag does not run at server - and even if it did I don't
think ASP.NET is coded to convert the ~ in that situation.
Now I suppose I could do something like use MapPath to dynamically figure
out what my document root structure was like at run time, and then do this:
<table border=0 width=100 background=" <% Response.Write(myRoot)
%>/images/something.gif"> but that would be VERY ugly and messy to do.
Certainly others have faced this so I am wondering if either I am just doing
something completely dumb and overlooking the obvious, or if not what is
being done about it the right way.
Worse case scenario - perhaps VS.NET 2005 b2 could just give me the option
to run without appending an application name when running locally in the
designer (just give me http://localhost:port/page.aspx and not
http://localhost:port/appName/page.aspx) .
Thanks,
Steve
"Juan T. Llibre" <nomailreplies@xxxxxxxxxxx> wrote in message
news:eL8836VuFHA.992@xxxxxxxxxxxxxxxxxxxxxxx
> Why are you running the table with "runat=server" ?
>
>
> Juan T. Llibre
> ASP.NET MVP
> ASP.NET FAQ : http://asp.net.do/faq/
> ==========================
>
> "Steve Franks" <please@xxxxxxxxxxxxxxxxx> wrote in message
> news:yt2dnWrm2dV67LXenZ2dnUVZ_s6dnZ2d@xxxxxxxxxxxxxx
>> Right. However there is a big catch here. What do you do for HTML that
>> needs to be written out that is not part of a server control?
>>
>> For example the BACKGROUND attribute of a HTML TABLE statement. You
>> cannot do:
>>
>> <table border=0 width=100 background="~/images/something.gif"
>> runat=server>
>>
>> That will just result in the HTML being sent to the browser literrally as
>> background="/~images/something.gif" which of course does not resolve so
>> the background image does not load.
>>
>> Same problem exists with stylesheets. For example if you need to specify
>> a URL in a style ***.
>>
>> What is the best way to handle that situation? Seems pretty messy.
>>
>> Thanks,
>>
>> Steve
>>
>> "Juan T. Llibre" <nomailreplies@xxxxxxxxxxx> wrote in message
>> news:egA0KtVuFHA.3628@xxxxxxxxxxxxxxxxxxxxxxx
>>> Use ~/images/whatever.gif
>>>
>>> The tilde ( ~ ) signifies the application's root in ASP.NET.
>>>
>>> All URLs will be relative to the root directory,
>>> no matter where they are physically located.
>>>
>>>
>>>
>>> Juan T. Llibre
>>> ASP.NET MVP
>>> ASP.NET FAQ : http://asp.net.do/faq/
>>> ==========================
>>>
>>> "Steve Franks" <please@xxxxxxxxxxxxxxxxx> wrote in message
>>> news:xqudnZ2dnZ2xb_3OnZ2dnZJejN6dnZ2dRVn-0J2dnZ0@xxxxxxxxxxxxxx
>>>>I am using VS.NET 2005 beta 2. When I run my project locally using the
>>>>default ASP.NET Development Web Server it runs using a root address like
>>>>this:
>>>> http://localhost:11243/testsite/
>>>>
>>>> However when I deploy to a remote test server running real IIS, the
>>>> real root of my application becomes:
>>>> http://localhost/
>>>>
>>>> What I want to do is have it so that on my local machine the asp.net
>>>> dev server does not use the virtual root, and instead uses:
>>>> http://localhost:11243/
>>>>
>>>> The reason for this is so that my URLs will work.
>>>>
>>>> For example I have to specify a background image url in my style
>>>> sheets, and a path like /images/whatever.gif is translating differently
>>>> depending on whether I run this locally in dev or remotely in
>>>> production.
>>>>
>>>> Thanks,
>>>>
>>>> Steve
>>>>
>>>
>>>
>>
>>
>
>
.
- Prev by Date: JavaScript version of VBScript's formatting functions
- Next by Date: Re: Another Newbie Question
- Previous by thread: JavaScript version of VBScript's formatting functions
- Next by thread: Re: How to remove virtual path from root url of dev web server?
- Index(es):