Search code examples
asp.netiisrootrelative-path

Root referencing on IIS for web application is not working, ASP.NET 4.0


I have weird problem with my IIS.

On my webserver I have an web application. Basically I converted folder into application and I assume that I did it all alright. I also consulted Microsoft directions from link below just to make sure that I didn't miss anything:

http://msdn.microsoft.com/en-us/library/ha2y9493.aspx

Anyway, now, in my application,

This doesn't work:

<img src="/images/7eleven.png" />

but, this works:

<img runat="server" src="~/images/7eleven.png" />

My physical path goes like this:

\\server\apps\myapplication\images

myapplication is .NET 4.0 WEB APPLICATION and I expect it to be an application root.

But, as far as I can see now, it is root only for server controls when runat="server" is used. Is there remedy for this?

Thanks.


Solution

  • Is the root of your site in IIS \\server\apps\myapplication\? As far as I can tell from your question, it is the root of the application, but you didn't say it is the root of the site.

    Clients don't know about application boundaries, so unless you have \\server\apps\myapplication\ at the root of your site, the absolute URL in your first example markup will not work.

    The remedy is to use a server-side control or code block to inject the proper path into the img src, as in your second example.