views:

24

answers:

1

I've just create a new ASP.NET Web Application in VS2010, and set it up as an application in IIS7.

Not sure if this is relevant, but the code physically resides in the \myserver\projects\epeui\epe folder (the projects folder is the root of my default web site). The application hangs off the root of this machine's default web site: http://myserver/epe/. And is configured as an application in IIS.

Normally, I used URLs that are relative to the application root, so my CSS files are in /styles/, my images are in /images/ and my JavaScript files are in /scripts/.

Given that the application is configured as such in IIS, to access my logo, I would expect to use /images/mylogo.png, an application-relative URL.

However, this doesn't work for this site; instead I need to use parent paths (../images/mylogo.png) or URLs relative to the default web site (/epe/images/mylogo.png). Neither of these are very good for portability reasons.

I've also tried using the tilde to use URLs that are supposedly relative to the virtual path (i.e. the application root) = ~/images/mylogo.png

I swear I've done this a thousand times before but clearly screwing up somewhere... Any suggestions?

Can someone at least confirm that, for a standard application in IIS, /mypage.html should reference http://myserver/myapp/mypage.html and not http://myserver/mypage.html?

+1  A: 

/mypage.html is going to map to the root http://myserver/mypage.html, this is correct behavior

The ~ on a SERVER SIDE control will map to the application root (so <asp:HyperLink NavigateUrl="~/mypage.html"...> will map to http://myserver/myapp/mypage.html

I have, in the past, especially with css and javascript files had to use <%= Request.ApplicationPath %>/myPage.html. Sometimes it's good to define that as a global variable in the global.asax.cs so you can use it all over. Request.ApplicationPath in your instance will be "/myapp"

I've struggled with this a lot too.

Jerzakie
Also a `<a href=~/mypage.html runat=server>` will work (because of that runat=server, asp.net processes the tag and the url).
Hans Kesting
Unless I'm losing my marbles (quite possible!), I could have sworn that I've spent the last 10 years developing ASP Classic applications, on various IIS versions, where '/' referred to the root of the application rather than the site. I'd often initially forget to set the folder as an application in IIS, and so these relative paths wouldn't work. Everything I've done in the last few years has been 'immune' to this problem so I'm now unsure whether there has been a change, or whether I'm in fact unhinged! :(
CJM