IIS子应用程序中的图像没有获得正确的路径 [英] Images in IIS sub application not getting correct path

查看:51
本文介绍了IIS子应用程序中的图像没有获得正确的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,

I deployed web application in my local iis under Default website.
The url is http://www.test.com/SubApplication/Controller/ActionResult
When i am giving some image path in html "/images/abc.jpg".I create the url "http://www.test.com/images/abc.jpg" but it should create "http://www.test.com/SubApplication/images/abc.jpg".Is there any setting in IIS for this.I googled but nothing found.





我尝试了什么:



我试图更改iis中的某些设置并尝试更改图像路径〜/ Images / abc.jpg并尝试更改路由,但没有任何工作



What I have tried:

I tried to change some settings in iis and also tried to change image path "~/Images/abc.jpg" and also tried to change routing but nothing works

推荐答案

使用@ Url.Content



Use @Url.Content

<img src="@Url.Content("~/images/abc.jpg")"/>


F-ES Sitecore建议的解决方案适合您。我只是添加了一些信息供您理解。

/ images / abc.jpg

开头的斜杠(/)表示来自网站根目录的路径。由于您的网站是www.test.com,/ images将返回此路径 - www.test.com/images。

如果我们在网站下托管我们的应用程序(通常在生产中完成)没有问题环境)。但是在本地系统中,我们通常将我们的网站指向默认网站下的应用程序,因为我们不需要创建任何域主机条目。在这种情况下,相对路径会产生问题。蒂尔德(〜)来救我们。在ASP.NET中使用Page.ResolveUrl到以〜开头的路径将为我们提供特定于我们应用程序的路径。在MVC中,我们可以使用 Url.Content 执行相同的操作。希望能给你一些澄清。
The solution suggested by F-ES Sitecore will work for you. I am just adding some more information for your understanding.
/images/abc.jpg
A slash (/) in the start indicates a path from the root of a website. Since your website is www.test.com, /images will return this path - www.test.com/images.
There is no problem if we host our application under a website (usually done in production environment). But in local system we usually point our website to an application under default website as we do not need to create any domain host entries then. In such cases, relative paths creates issues. Tilde (~) comes to our rescue. In ASP.NET using Page.ResolveUrl to a path starting with ~ would give us path specific to our application. In MVC we can do the same using Url.Content. Hope that gives you some clarification.


这篇关于IIS子应用程序中的图像没有获得正确的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆