I have hosted my asp .net mvc3 application in iis server 7. I had deployed my application under a virtual directory and url to my application is like http://www.abc.com/virtualdirname . Application works fine and Im able to navigate through pages. However , Im unable to view any images used in my application. I have stored my images in a folder public/images .
cshtml code for one of the image is as follows
img id=”start” src=”../../Public/images/start_button_start.png”
Im getting error message in place of images and path of image is http://www.abc.com/public/images instead of http://www.abc.com/virtualdirname/public/images .
In the app settings of my config file, I had defined virtual dir.
add key=”virtualdir” value=”/virtualdirname ” /
Can anyone tell me why this problem happens and how can I get out of this?
Never hardcode urls in an ASP.NET MVC application. Always use url helpers:
Url helpers will take virtual directory into account.