我可以使用 HTML 基本标签来解析虚拟目录吗?
我有一个 ASP.NET MVC Web 应用程序作为子网在 IIS 中运行;假设它的路径类似于 http://mysite.com/subweb。
我有一个提供从 CMS 获取的内容的视图。 CMS 编辑器已输入一些包含相对图像路径 的内容。
这在站点是根网站的生产服务器上工作正常,但在站点是根网站下的虚拟目录的临时服务器上则
不起作用路径应该是 在生产服务器上
和 在临时服务器上。
是否可以使用
<head>
<base href="http://mysite.com/subweb/" />
</head>
<html>
<body>
<img src="/images/imga.png" />
</body>
</html>
这似乎不起作用。谁能解释为什么或者这是否是一种可行的方法?我不想要求内容编辑者了解网站部署选项(该选项在 UAT 和生产之间变化)。
I have an ASP.NET MVC web application running in IIS as a subweb; let's say its path is something like http://mysite.com/subweb.
I have a view which serves content obtained from a CMS. The CMS editor has entered some content containing a relative image path <img src="/images/imga.png" />.
This works fine on the production server where the site is the root website, but not on the staging server where the site is a virtual directory under the root website
The path should be <img src="/images/imga.png" /> on the production server
and <img src="/subweb/images/imga.png" /> on the staging server.
Is it possible to use the <base> tag to resolve this image path?
<head>
<base href="http://mysite.com/subweb/" />
</head>
<html>
<body>
<img src="/images/imga.png" />
</body>
</html>
It doesn't seem to work. Can anyone explain why or if this is a workable approach? I don't want to require the content editor to have knowledge of the website deployment option (which changes between UAT and production).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
将其设为相对 URL。当然没那么容易,内容编辑器必须要换。但我确实相信这就是问题所在。以
/
开头的 URL 是从域的顶级目录解析的(奇怪)?Try
to make it a relative URL. Of course it's not that easy, the content editor must be changed. But I do believed that is the problem. URLs starting with a
/
are resolved from... (wonders) the domain's top-level directory?基本标记仅影响相对 URL。尝试将图像标签更改为:
即使在应用程序的子目录中,这也将起作用。 .Net 会将“~/”解析为您的应用程序根目录。
The base tag only affects relative URLs. Try changing your image tag to this:
This will work even in sub directories of your app. .Net will resolve the "~/" to your application root.