bobetko
bobetko

Reputation: 5168

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.

Upvotes: 1

Views: 897

Answers (2)

pseudocoder
pseudocoder

Reputation: 4392

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.

Upvotes: 2

huMpty duMpty
huMpty duMpty

Reputation: 14460

I think its better to use Server.MapPath("~")

This will explain it further ASP.NET Web Project Paths

Upvotes: 0

Related Questions