I have an IIS web application called "WebApp" created inside the "Default Web Site". The WebApp has a virutal directory with a repository of images called "Repository".
Schema:
-Default Web Site
-WebApp
-Repository
When I execute the web application like this:
http://localhost/WebApp
All my images points to a relative url like "/Repository/ImageDir/image.jpg
" which is interpreted like http://localhost/Repository/ImageDir/image.jpg
.
That URL is wrong, because since my virtual directory is inside WebApp
, the correct URL should be http://localhost**/WebApp**/Repository/ImageDir/image.jpg
How can I make it generate a correct URL.
Just for more info, the web application is in ASP.NET MVC.
UPDATE:
I'm using Razor in my views, so here is the code to generate a img tag:
<img src="@m.ThumbPath" />
Where "m" is an element of the Model (which is a List of elements) and "ThumbPath" contains the relative path that is giving problems.
由于您使用的是Asp.Net MVC,因此您应该使用Url.Content -helper来生成应用内部资源的URL:
<img src="@Url.Content(String.Format("~{0}", m.ThumbPath))">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.