ASP.NET条件标记渲染据Web.config中的关键 [英] ASP.NET Conditional Markup Rendering According to Web.config Key
问题描述
我在web.config中的一个关键 -
I have a key in web.config as -
<add key="IsDemo" value ="true"/>
我想上面显示为非服务器html标记的web.config项基于/隐藏标记不使用code隐藏文件(因为没有cs文件,有没有RUNAT =服务器控件)。
一些类似于下面的伪code:
I want to show/hide markup based on above web.config entry for a non-server html tag without using code behind file (as there is no .cs file and there are no runat=server controls). Something similar to following pseudo code:
IF ( IsDemo == "true" )
THEN
<tr>
<td id="tdDemoSection" colspan="2" align="left" valign="top">
<.....>
</td>
</tr>
ENDIF
有谁知道,我们可以在标记的.aspx写这样的条件逻辑?
请帮助!
Does anyone know that we can write such conditional logic in .aspx markup? Please help!!!
编辑:
部分我隐藏或显示有像用户名和密码的一些数据。所以,我不希望用户使用萤火虫或Web开发工具查看隐藏的标记。标记不应该去客户端。
Section I'm hiding or showing have some data like username and password. So, I do not want user to use Firebug or Web Developer Tools to see hidden markup. markup should not go to client side.
推荐答案
类似的东西的语法是
<% if(System.Configuration.ConfigurationManager.AppSettings["IsDemo"] == "true") %>
<% { %>
<!-- Protected HTML goes here -->
<% } %>
这假设页面是在C#。
This assumes that the page is in C#.
您可以通过被周围的AppSettings的检索例如更多的防守坚挺code起来在值为null等的情况下会发生什么。
You can firm this code up by being more defensive around the AppSettings retrieval e.g. what happens in the case where the value is null etc.
这篇关于ASP.NET条件标记渲染据Web.config中的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!