gpt4 book ai didi

c# - 将 Web 应用程序部署到 IIS 时,图像未加载到中继器内

转载 作者:太空狗 更新时间:2023-10-30 01:00:12 25 4
gpt4 key购买 nike

我已经按照 Microsoft Docs (Deploy to Test) 部署了我的 asp.net web 应用程序.

将我的应用程序部署到 IIS 后,出现 Repeater 控件内的图像未加载的问题。在调试/开发过程中,这些正在正确加载。

下面是我的代码(带图像控制的中继器):

<asp:Repeater ID="rpBanquetList" runat="server">
<ItemTemplate>
//... other controls
<asp:Image ID="imgImagePath" ImageUrl='<%#"Images/"+Eval("imgImagePath") %>'
runat="server" />
//... other controls
</ItemTemplate>
</asp:Repeater>

Windows 7:IIS 8:VS15 社区

最佳答案

您可能遇到了相对 URL 的问题。您可以尝试以下操作:

<asp:Repeater ID="rpBanquetList" runat="server">
<ItemTemplate>
//... other controls
<asp:Image ID="imgImagePath" ImageUrl='<%#"~/Images/"+Eval("imgImagePath") %>'
runat="server" />
//... other controls
</ItemTemplate>

您的图像可能位于 AppRootDirectory\Images\ 中,并且您正在尝试从与 AppRootDirectory 不同的目录中的页面访问它们,比方说 AppRootDirectory\MyWebform\pageWithRepeaterControl.aspx。在这种情况下,图像的相对 URL 将被解析为如下内容:

http://hostName/appName/MyWebForm/Images/ + 来自 Eval("imgImagePath") 的值。请注意,此处的 /Images/ 被解释为 appName 的子目录。

请注意 appName 可能是也可能不是您项目 URL 的一部分。这取决于您如何部署 Web 应用程序,是在 IIS 中的网站根目录中还是作为此类网站中的应用程序。

您可以使用~ 运算符获取相对于根目录的路径。使用与之前相同的示例,~/Images/ 将解析为 http://hostName/appName/Images/,即 AppRootDirectory\Images\ 服务器中的物理路径。

关于 web project paths here 的更多信息

希望对您有所帮助。

关于c# - 将 Web 应用程序部署到 IIS 时,图像未加载到中继器内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48504871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com