문제

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:

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...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top