By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,182 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,182 IT Pros & Developers. It's quick & easy.

Need help with URI path

P: n/a
Hello,

I'm not sure if these are the appropriate forums for my question since
it is closer to about Visual Studio 2005 than it is about .NET
framework. So please pardon me and direct me to a different forum if I
made a mistake. In any case, thank you for spending the time to read
this loooong case and/or for your input.

With that said, here's the background of the situation:

----- Scenario -----
I have created a web project using VS2005.
The file structure as seen from the /Solution Explorer/ is as the following:
- Solution label/filename/location
- Project label/filename/location
- App_Code
- css
- style.css
- imgs
- image.jpg
- js
- script.js
- main.aspx

The content of style.css in discussion is:
/*----- CSS -----*/
.StyleClassName
{
background: url(/imgs/image.jpg) no-repeat 0% 100%;
font-size: 10pt;
}
/*----- End CSS Excerpt -----*/

The content of main.aspx in discussion is:
/*----- ASP.Net -----*/
<link rel="stylesheet" media="all" type="text/css"
href="css/style.css" />
...
<div id="div1" class="StyleClassName">Test</div>
/*----- End ASP.Net Excerpt -----*/

Everything is dandy, except for the image not displaying.
----- End Scenario -----

The question is:
- How can I configure Visual Studio, so that when I click Build/Start
(F5) the image displays according to its path designation (from the web
root)?

What I've tried:
- I tried hard coding the path into the URL descriptor, e.g.: changing
(/imgs/image.jpg) to
(http://localhost:port/projectLabel/imgs/image.jpg). This works, but I
don't like having to remember to change the hard code back when I
publish to the real IIS server (which has no problem with the original
descriptor) and back again when I continue coding.
- The original path is relative to the application web root, a practice
which I very much like, since the root is usually the only constant in a
web project. But for this purpose, I even tried using (imgs/image.jpg)
for kicks, but doesn't work. Also tried a few others like
(../imgs/image.jpg), (../../imgs/image.jpg), (/../imgs/image.jpg), and
(/../../imgs/image.jpg), one of them (the 1st) works, but it isn't
semantically correct when published again with a different root
directory, right? It's like saying, "Go back up one, two or three
directory levels to try to find the web root then from the web root find
imgs/image.jpg," instead of just saying: "you know where the root is,
from there find imgs/image.jpg." I mean I would be forced to do this
anyway if there's no answer to this question.

In VS.2003 or earlier this wasn't have been a problem since the IIS
application directory is setup to start at the project directory, so
that the web root follows the server's definition. (There were other
problems I realize but that's a different topic).

So... Is there a way to configure the IDE with a single-click option so
that it /works/ as expected? (Other than of using the "Use custom
Server, then start specifying everything manually again to mimic VS.2003
IIS setup).

Thanks again.
`Js.
Dec 8 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
when a relative url starts with /, that means start from the hostname,
not the current dir.

say your url is

http://myhost.com/mysite/mypage.aspx

then the browser

/img/img.gif will resolve to http://myhost.com/img/img.gif

img/img.gif will resolve to http://myhost.com/mysite/img/img.gif
-- bruce (sqlwork.com)
John Smith wrote:
Hello,

I'm not sure if these are the appropriate forums for my question since
it is closer to about Visual Studio 2005 than it is about .NET
framework. So please pardon me and direct me to a different forum if I
made a mistake. In any case, thank you for spending the time to read
this loooong case and/or for your input.

With that said, here's the background of the situation:

----- Scenario -----
I have created a web project using VS2005.
The file structure as seen from the /Solution Explorer/ is as the
following:
- Solution label/filename/location
- Project label/filename/location
- App_Code
- css
- style.css
- imgs
- image.jpg
- js
- script.js
- main.aspx

The content of style.css in discussion is:
/*----- CSS -----*/
.StyleClassName
{
background: url(/imgs/image.jpg) no-repeat 0% 100%;
font-size: 10pt;
}
/*----- End CSS Excerpt -----*/

The content of main.aspx in discussion is:
/*----- ASP.Net -----*/
<link rel="stylesheet" media="all" type="text/css"
href="css/style.css" />
...
<div id="div1" class="StyleClassName">Test</div>
/*----- End ASP.Net Excerpt -----*/

Everything is dandy, except for the image not displaying.
----- End Scenario -----

The question is:
- How can I configure Visual Studio, so that when I click Build/Start
(F5) the image displays according to its path designation (from the web
root)?

What I've tried:
- I tried hard coding the path into the URL descriptor, e.g.: changing
(/imgs/image.jpg) to
(http://localhost:port/projectLabel/imgs/image.jpg). This works, but I
don't like having to remember to change the hard code back when I
publish to the real IIS server (which has no problem with the original
descriptor) and back again when I continue coding.
- The original path is relative to the application web root, a practice
which I very much like, since the root is usually the only constant in a
web project. But for this purpose, I even tried using (imgs/image.jpg)
for kicks, but doesn't work. Also tried a few others like
(../imgs/image.jpg), (../../imgs/image.jpg), (/../imgs/image.jpg), and
(/../../imgs/image.jpg), one of them (the 1st) works, but it isn't
semantically correct when published again with a different root
directory, right? It's like saying, "Go back up one, two or three
directory levels to try to find the web root then from the web root find
imgs/image.jpg," instead of just saying: "you know where the root is,
from there find imgs/image.jpg." I mean I would be forced to do this
anyway if there's no answer to this question.

In VS.2003 or earlier this wasn't have been a problem since the IIS
application directory is setup to start at the project directory, so
that the web root follows the server's definition. (There were other
problems I realize but that's a different topic).

So... Is there a way to configure the IDE with a single-click option so
that it /works/ as expected? (Other than of using the "Use custom
Server, then start specifying everything manually again to mimic VS.2003
IIS setup).

Thanks again.
`Js.
Dec 8 '06 #2

P: n/a
Right. I forgot to mention I tried that too. But the problem this one is
that I think this is relative to the .css file and not to the .aspx
file. And while it works using the "Build Style..." menu item and
created exactly that, when run it couldn't recognize it (me thinks
probably) because it resolves to:
http://localhost:port/projectLabel/_...imgs/image.jpg, instead of
the expected:
http://localhost:port/projectLabel/imgs/image.jpg

Thank you still.
`Js.
Adriano .NET wrote:
It looks like in your .css file you have the first slash of the image path
unneeded.
Try this:
background: url(imgs/image.jpg) no-repeat 0% 100%;

instead of:
background: url(/imgs/image.jpg) no-repeat 0% 100%;

When you're building a style using VS2005 and you've got some problems like
this just try to right click inside the style definition of the css file and
select Build Style... and every single little issue disappear after you
confirm.

For me it's perfectly working.

Regards, Adriano Palmieri.

"John Smith" wrote:

>Hello,

I'm not sure if these are the appropriate forums for my question since
it is closer to about Visual Studio 2005 than it is about .NET
framework. So please pardon me and direct me to a different forum if I
made a mistake. In any case, thank you for spending the time to read
this loooong case and/or for your input.

With that said, here's the background of the situation:

----- Scenario -----
I have created a web project using VS2005.
The file structure as seen from the /Solution Explorer/ is as the following:
- Solution label/filename/location
- Project label/filename/location
- App_Code
- css
- style.css
- imgs
- image.jpg
- js
- script.js
- main.aspx

The content of style.css in discussion is:
/*----- CSS -----*/
.StyleClassName
{
background: url(/imgs/image.jpg) no-repeat 0% 100%;
font-size: 10pt;
}
/*----- End CSS Excerpt -----*/

The content of main.aspx in discussion is:
/*----- ASP.Net -----*/
<link rel="stylesheet" media="all" type="text/css"
href="css/style.css" />
...
<div id="div1" class="StyleClassName">Test</div>
/*----- End ASP.Net Excerpt -----*/

Everything is dandy, except for the image not displaying.
----- End Scenario -----

The question is:
- How can I configure Visual Studio, so that when I click Build/Start
(F5) the image displays according to its path designation (from the web
root)?

What I've tried:
- I tried hard coding the path into the URL descriptor, e.g.: changing
(/imgs/image.jpg) to
(http://localhost:port/projectLabel/imgs/image.jpg). This works, but I
don't like having to remember to change the hard code back when I
publish to the real IIS server (which has no problem with the original
descriptor) and back again when I continue coding.
- The original path is relative to the application web root, a practice
which I very much like, since the root is usually the only constant in a
web project. But for this purpose, I even tried using (imgs/image.jpg)
for kicks, but doesn't work. Also tried a few others like
(../imgs/image.jpg), (../../imgs/image.jpg), (/../imgs/image.jpg), and
(/../../imgs/image.jpg), one of them (the 1st) works, but it isn't
semantically correct when published again with a different root
directory, right? It's like saying, "Go back up one, two or three
directory levels to try to find the web root then from the web root find
imgs/image.jpg," instead of just saying: "you know where the root is,
from there find imgs/image.jpg." I mean I would be forced to do this
anyway if there's no answer to this question.

In VS.2003 or earlier this wasn't have been a problem since the IIS
application directory is setup to start at the project directory, so
that the web root follows the server's definition. (There were other
problems I realize but that's a different topic).

So... Is there a way to configure the IDE with a single-click option so
that it /works/ as expected? (Other than of using the "Use custom
Server, then start specifying everything manually again to mimic VS.2003
IIS setup).

Thanks again.
`Js.

Dec 9 '06 #3

P: n/a
Right. I forgot to mention I tried that too. But the problem this one is
that I think this is relative to the .css file and not to the .aspx
file. And while it works using the "Build Style..." menu item and
created exactly that, when run it couldn't recognize it (me thinks
probably) because it resolves to:
http://localhost:port/projectLabel/_...imgs/image.jpg, instead of
the expected:
http://localhost:port/projectLabel/imgs/image.jpg

Thank you still.
`Js.
Adriano .NET wrote:
It looks like in your .css file you have the first slash of the image path
unneeded.
Try this:
background: url(imgs/image.jpg) no-repeat 0% 100%;

instead of:
background: url(/imgs/image.jpg) no-repeat 0% 100%;

When you're building a style using VS2005 and you've got some problems like
this just try to right click inside the style definition of the css file and
select Build Style... and every single little issue disappear after you
confirm.

For me it's perfectly working.

Regards, Adriano Palmieri.

"John Smith" wrote:

>Hello,

I'm not sure if these are the appropriate forums for my question since
it is closer to about Visual Studio 2005 than it is about .NET
framework. So please pardon me and direct me to a different forum if I
made a mistake. In any case, thank you for spending the time to read
this loooong case and/or for your input.

With that said, here's the background of the situation:

----- Scenario -----
I have created a web project using VS2005.
The file structure as seen from the /Solution Explorer/ is as the following:
- Solution label/filename/location
- Project label/filename/location
- App_Code
- css
- style.css
- imgs
- image.jpg
- js
- script.js
- main.aspx

The content of style.css in discussion is:
/*----- CSS -----*/
.StyleClassName
{
background: url(/imgs/image.jpg) no-repeat 0% 100%;
font-size: 10pt;
}
/*----- End CSS Excerpt -----*/

The content of main.aspx in discussion is:
/*----- ASP.Net -----*/
<link rel="stylesheet" media="all" type="text/css"
href="css/style.css" />
...
<div id="div1" class="StyleClassName">Test</div>
/*----- End ASP.Net Excerpt -----*/

Everything is dandy, except for the image not displaying.
----- End Scenario -----

The question is:
- How can I configure Visual Studio, so that when I click Build/Start
(F5) the image displays according to its path designation (from the web
root)?

What I've tried:
- I tried hard coding the path into the URL descriptor, e.g.: changing
(/imgs/image.jpg) to
(http://localhost:port/projectLabel/imgs/image.jpg). This works, but I
don't like having to remember to change the hard code back when I
publish to the real IIS server (which has no problem with the original
descriptor) and back again when I continue coding.
- The original path is relative to the application web root, a practice
which I very much like, since the root is usually the only constant in a
web project. But for this purpose, I even tried using (imgs/image.jpg)
for kicks, but doesn't work. Also tried a few others like
(../imgs/image.jpg), (../../imgs/image.jpg), (/../imgs/image.jpg), and
(/../../imgs/image.jpg), one of them (the 1st) works, but it isn't
semantically correct when published again with a different root
directory, right? It's like saying, "Go back up one, two or three
directory levels to try to find the web root then from the web root find
imgs/image.jpg," instead of just saying: "you know where the root is,
from there find imgs/image.jpg." I mean I would be forced to do this
anyway if there's no answer to this question.

In VS.2003 or earlier this wasn't have been a problem since the IIS
application directory is setup to start at the project directory, so
that the web root follows the server's definition. (There were other
problems I realize but that's a different topic).

So... Is there a way to configure the IDE with a single-click option so
that it /works/ as expected? (Other than of using the "Use custom
Server, then start specifying everything manually again to mimic VS.2003
IIS setup).

Thanks again.
`Js.

Dec 9 '06 #4

P: n/a
Oops... btw, sorry for the duplicate response on the other post,
double-clicked send by accident (instead of one click).
Yes, Bruce, I understand that when I used the slash it means it starts
from the webroot.
In regular IIS (Windows Server) installation the webroot happens to be
the hostname, and for the Windows XP workstation version the webroot
happens to be the application directory, and thus it /could (and usually
does)/ resolve to:
http://localhost/appDirectory/imgs/image.jpg.

But in the case for VS2005, for some reason it resolves back to the
hostname as you indicated and is not the sought effect since when it
resolves to the hostname it actually resolves to:
http://localhost:port/imgs/image.jpg.
instead of the expected:
http://localhost:port/projectLabel/imgs/image.jpg
I didn't want this during development with VS2005 (since the IDE is
mostly nifty and all :))

But when I publish to the actual Windows Server IIS installation, yes, I
am ok with it resolving to:
http://domainName/imgs/image.jpg
since that is how the it's supposed to work anyway.

As far as trying with relative path of just img/image.jpg, please see my
other response about its observed resolution.

Thank you for your input.
`Js.

PS. I tried with numerous combination of slashes and up-dir-double-dots
not because I didn't know the slash theory/concept :) but because the
IIS and VS.NET behaviors don't seem to follow the expected standard
behaviors. We all know that Microsoft often does things a bit
differently than the standard, but still, since I am not a Microsoft
basher, I thought maybe it's just my ignorance of the way the IDE is
supposed to be configured. :P :)
bruce barker wrote:
when a relative url starts with /, that means start from the hostname,
not the current dir.

say your url is

http://myhost.com/mysite/mypage.aspx

then the browser

/img/img.gif will resolve to http://myhost.com/img/img.gif

img/img.gif will resolve to http://myhost.com/mysite/img/img.gif
-- bruce (sqlwork.com)
John Smith wrote:
>Hello,

I'm not sure if these are the appropriate forums for my question
since it is closer to about Visual Studio 2005 than it is about .NET
framework. So please pardon me and direct me to a different forum if
I made a mistake. In any case, thank you for spending the time to
read this loooong case and/or for your input.

With that said, here's the background of the situation:

----- Scenario -----
I have created a web project using VS2005.
The file structure as seen from the /Solution Explorer/ is as the
following:
- Solution label/filename/location
- Project label/filename/location
- App_Code
- css
- style.css
- imgs
- image.jpg
- js
- script.js
- main.aspx

The content of style.css in discussion is:
/*----- CSS -----*/
.StyleClassName
{
background: url(/imgs/image.jpg) no-repeat 0% 100%;
font-size: 10pt;
}
/*----- End CSS Excerpt -----*/

The content of main.aspx in discussion is:
/*----- ASP.Net -----*/
<link rel="stylesheet" media="all" type="text/css"
href="css/style.css" />
...
<div id="div1" class="StyleClassName">Test</div>
/*----- End ASP.Net Excerpt -----*/

Everything is dandy, except for the image not displaying.
----- End Scenario -----

The question is:
- How can I configure Visual Studio, so that when I click Build/Start
(F5) the image displays according to its path designation (from the
web root)?

What I've tried:
- I tried hard coding the path into the URL descriptor, e.g.:
changing (/imgs/image.jpg) to
(http://localhost:port/projectLabel/imgs/image.jpg). This works, but
I don't like having to remember to change the hard code back when I
publish to the real IIS server (which has no problem with the
original descriptor) and back again when I continue coding.
- The original path is relative to the application web root, a
practice which I very much like, since the root is usually the only
constant in a web project. But for this purpose, I even tried using
(imgs/image.jpg) for kicks, but doesn't work. Also tried a few others
like (../imgs/image.jpg), (../../imgs/image.jpg),
(/../imgs/image.jpg), and (/../../imgs/image.jpg), one of them (the
1st) works, but it isn't semantically correct when published again
with a different root directory, right? It's like saying, "Go back up
one, two or three directory levels to try to find the web root then
from the web root find imgs/image.jpg," instead of just saying: "you
know where the root is, from there find imgs/image.jpg." I mean I
would be forced to do this anyway if there's no answer to this question.

In VS.2003 or earlier this wasn't have been a problem since the IIS
application directory is setup to start at the project directory, so
that the web root follows the server's definition. (There were other
problems I realize but that's a different topic).

So... Is there a way to configure the IDE with a single-click option
so that it /works/ as expected? (Other than of using the "Use custom
Server, then start specifying everything manually again to mimic
VS.2003 IIS setup).

Thanks again.
`Js.
Dec 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.