开发者

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

开发者 https://www.devze.com 2023-04-04 22:48 出处:网络
I have an ASP.NET MVC 3 website which is running on http://localhost/. I also have a new 开发者_StackOverflow社区project (ASP.NET MVC3) and I want to deploy it as application

I have an ASP.NET MVC 3 website which is running on http://localhost/. I also have a new 开发者_StackOverflow社区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?


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.


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, ...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号