ASP.Net映像将ImageURL设置为外部站点

时间:2013-12-17 10:05:03

标签: asp.net vb.net

我正在努力在asp:image控件中设置ImageURL。我将它设置为来自另一个站点的URL,目前我有几个版本的图像试图让一个工作下面是我的代码和输出。

图像中使用的功能

Function BuildLogoPath() As String
    Return ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg"
End Function

页面

中的ASP.net代码
<asp:Image ID="imgFav" runat="server" ImageUrl='<%: ConfigurationManager.AppSettings("WebPath") & "img/favicon.ico" %>' /><br />
<asp:Image ID="Image2" runat="server" ImageUrl='<%= ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg" %>' />
<asp:Image ID="Image3" runat="server" ImageUrl='<% ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg" %>' />
<asp:Image ID="Image4" runat="server" ImageUrl='<% Response.write(ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg") %>' />
<asp:Image ID="imgLogo" runat="server" ImageUrl='<%# BuildLogoPath() %>' /><br />
<asp:Image ID="Image5" runat="server" ImageUrl='<%= BuildLogoPath() %>' />
<asp:Image ID="Image6" runat="server" ImageUrl='<% BuildLogoPath() %>' />
<asp:Image ID="Image7" runat="server" ImageUrl='<% response.write(BuildLogoPath()) %>' />
<%= ConfigurationManager.AppSettings("WebPath") & "img/favicon.ico" %><br />
<%= ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg" %>

输出:

<img id="ContentPlaceHolder1_imgFav" src="<%:%20ConfigurationManager.AppSettings(&quot;WebPath&quot;)%20&amp;%20&quot;img/favicon.ico&quot;%20%>"><br>
<img id="ContentPlaceHolder1_Image2" src="<%=%20ConfigurationManager.AppSettings(&quot;WebPath&quot;)%20&amp;%20&quot;/img/main/logo.jpg&quot;%20%>">
<img id="ContentPlaceHolder1_Image3" src="<%%20ConfigurationManager.AppSettings(&quot;WebPath&quot;)%20&amp;%20&quot;/img/main/logo.jpg&quot;%20%>">
<img id="ContentPlaceHolder1_Image4" src="<%%20Response.write(ConfigurationManager.AppSettings(&quot;WebPath&quot;)%20&amp;%20&quot;/img/main/logo.jpg&quot;)%20%>">
<img id="ContentPlaceHolder1_imgLogo" src=""><br>
<img id="ContentPlaceHolder1_Image5" src="<%=%20BuildLogoPath()%20%>">
<img id="ContentPlaceHolder1_Image6" src="<%%20BuildLogoPath()%20%>">
<img id="ContentPlaceHolder1_Image7" src="<%%20response.write(BuildLogoPath())%20%>">
http://office.logma.biz/onefit.com.jamie/img/favicon.ico<br>
http://office.logma.biz/onefit.com.jamie//img/main/logo.jpg

正如您所看到的,代码在不在图像控件中时工作正常。

1 个答案:

答案 0 :(得分:1)

简单的答案是,您无法在<%标记内使用%><asp: .. />。您有两种选择:

  1. 以编程方式从代码隐藏设置:

    imgFav.ImageUrl = Me.BuildLogoPath()

  2. 在HTML中呈现正常的<img>标记:

    <img src='<%= BuildLogoPath() %>' />