Yaplex
Yaplex

Reputation: 2284

ASP.NET MVC 3 - Images not found if deploy as application on IIS 7.5

I have an ASP.NET MVC 3 website which is running on http://localhost/. I also have a new project (ASP.NET MVC3) and I want to deploy it as application so the url will look like http://localhost/child/

But I have problems with images. If I create image using <img src="/content/img/site-logo.png" alt="logo" /> the image is not available, because the actual URL should be /child/content/img/site-logo.png.

I can solve it if I put url in Url.Content("~/content/img/site-logo.png") but I don't want to change all my images now.

Is it some more easy solution? Some IIS 7 settings?

Upvotes: 3

Views: 1958

Answers (3)

bassem
bassem

Reputation: 51

I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.

When a user is not logged in yet, they are classified as Anonymous Authentication. In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder.

That fixed it for me, hope it works for you.

Upvotes: 2

Dima
Dima

Reputation: 6741

You can create virtual directory in root iis project and point it on directory with images. BUT, you should better spend this time to clean up your image paths because it, probably, will bite you in future again.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

I can solve it if I put url in Url.Content("~/content/img/site-logo.png") but I don't want to change all my images now.

I am not aware of any IIS setting, other than of course setting your application to run at the root of the IIS web site.

You should always use url helpers when dealing with urls in an ASP.NET MVC application. So you really should change all hardcoded urls, and by the way this doesn't include only images, it could be also anchor hrefs, form actions, hardcoded urls in your javascript files, ...

Upvotes: 0

Related Questions