开发者

Problem with displaying images in MVC with a virtual directory configured

I have a MVC application hosted on a IIS 7.5 In my project I have a local images folder in a different location that is configured in IIS as a virtual directory say /otherimages

When I try to reference this path from the view开发者_StackOverflow社区 it doesn't display the images, images that are hosted in /Content folder work perfectly, how can I configure this to work.

I tried

Url.Content("~/otherimages/pic.jpg")

but plain img tag doesn't work either.

Thank you


I'm not sure I exactly understand the question, but I'll have a stab.

If you've set up a virtual directory that includes the images, the chances are, that directory is at the root of the website. So, http://localhost/otherimages.

If this is the case, Url.Content("~/otherimages/pic.jpg") will not work as it is looking the the root of the web application (at http://localhost/myapp/otherimages). What it sounds like you need to do is something like:

Url.Content("/otherimages/pic.jpg")

This is basically removing the tilde "~" and forcing the Url.Content() to look at the website root, rather than the web application root.

Note: This means your app is reliant upon an external directory existing in a specific location with a specific name. If you're happy with that, then all is well :)


that should work. i would check permissions. Go have a look at the IIS logs to see if you get a response other than 200 status.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜