开发者

ASP.NET ExpressionBuilder syntax - output AppSetting within img tag

I would like to use ASP.NET's ExpressionBuilder syntax to dynamically retrieve domain of static content from an AppSetting.

I am using the following syntax, which does not work:

<img src="<%$Appsettings:STATIC_CONTENT_DOMAIN %>/img/logo.jpg" alt="logo" width="176" height="159" />

FYI, the desired HTML output is:

<img开发者_开发百科 src="http://static.myserver.com/img/logo.jpg" alt="logo" width="176" height="159" />

Please note, I cannot use <%= %> syntax because my ASPX page needs to be CompilationMode="never". (The reason I am using ExpressionBuilder syntax is that it works in no-compile pages)

Any ideas on how I can do this?


This approach worked for me (not very readable :)...

<img src="<asp:Literal runat='server' Text='<%$Appsettings:STATIC_CONTENT_DOMAIN%>'/>/img/logo.jpg" />


You might want to consider writing a custom expression builder - they're not too difficult to write. Here are some tutorials:

  • Express Yourself With Custom Expression Builders
  • Expression Builders in ASP.NET 2.0

You could have your own expression syntax such as:

<%$ MyCdnUrl: Static, '/img/logo.jpg' %>

Then you'd parse out everything after the ":" and build up the URL that you need.

I think that expression builders must be used as "property values" so you can't use them completely on their own. You'll still have to use something like <img runat="server"> or an <asp:Image> control or an <img> with the <asp:Literal> inside it.


I believe you need to use a server-side asp.net control, such as:

<asp:Image ID="MyImage" runat="server" ImageUrl="<%$Appsettings:STATIC_CONTENT_DOMAIN %>" />

I don't know if you can combine the statement with static info like you have, such as:

<asp:Image ID="MyImage" runat="server" ImageUrl="<%$Appsettings:STATIC_CONTENT_DOMAIN %>/img/logo.jpg" />

My guess would be it isn't possible, but I guess it's worth a shot. Try it out and see...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜