我可以使用 HTML 基本标签来解析虚拟目录吗?

发布于 2024-09-06 01:54:11 字数 703 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铁憨憨 2024-09-13 01:54:11

尝试

   <img src="images/imga.png" />

将其设为相对 URL。当然没那么容易,内容编辑器必须要换。但我确实相信这就是问题所在。以 / 开头的 URL 是从域的顶级目录解析的(奇怪)?

Try

   <img src="images/imga.png" />

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?

一念一轮回 2024-09-13 01:54:11

基本标记仅影响相对 URL。尝试将图像标签更改为:

<img runat="server" src="~/images/imga.png" />

即使在应用程序的子目录中,这也将起作用。 .Net 会将“~/”解析为您的应用程序根目录。

The base tag only affects relative URLs. Try changing your image tag to this:

<img runat="server" src="~/images/imga.png" />

This will work even in sub directories of your app. .Net will resolve the "~/" to your application root.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文