【问题标题】:Can I use an absolute url in an html img tag on a IIS7 ASP.NET application?我可以在 IIS7 ASP.NET 应用程序的 html img 标记中使用绝对 url 吗?
【发布时间】:2011-02-07 23:56:16
【问题描述】:

在将 ASP.NET Intranet 应用程序从 IIS6 迁移到 IIS7 时,我遇到了 html 标记中的绝对 url 的问题:我无法让他们将应用程序视为 url 的根,除非应用程序在网站的根目录。

这是一个演示问题的代码 sn-p。它发布在“默认网站”下的应用程序中。

前两个图像显示在浏览器中。第三个没有:

<body>
    <form id="form1" runat="server">

        Absolute path using asp image control: 
        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/image.png" /> 

        Relative path using html img tag:  
        <img alt="Works just fine" src="images/image.png" />

        Absolute path using html img tag:   
        <img alt="WTF?" src="/images/image.png" />

    </form>
</body>

在 localhost 上运行时,所有三个图像都能正常显示。

问题是“/images/image.png”在默认网站中查找名为“images”的目录,而不是在应用程序中。

有什么方法可以设置应用程序,使其根目录与 html url 的根目录相同?非常感谢您提供任何帮助!

  • 克里斯

【问题讨论】:

    标签: html url iis-7 absolute


    【解决方案1】:

    你也可以通过使用实现你想要的

    <img alt="This works, too." src="images/image.png" runat="server" />
    

    【讨论】:

      猜你喜欢
      • 2010-10-17
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      相关资源
      最近更新 更多