如何阅读HTML标记中的web.config APP密钥设置 [英] How to read web.config APP key settings in HTML markup
问题描述
我有一个使用第三方activeX控件的ASP.NET网站。我必须将一些参数传递给HTML页面中的OBJECT标签。如果我硬编码这些参数到HTML一切正常。
I have an ASP.NET site which uses a 3rd party activeX control. I have to pass a few parameters to the OBJECT tag in the HTML page. If i hardcode these parameters into the HTML everything works.
我想将这些参数放在我的web.config中,并带有应用程序设置键/值对。
I would like to place the parameters in my web.config with app settings "key/value" pairs.
我的问题是我无法读取HTML标记中的应用程序键设置,以成功传递它们作为参数。我可以从后面的服务器端代码读取它们。
My problem is i cannot read the app key setting in the HTML markup to succesfully pass them in as parameters. I can read them fine from server side code behind.
在客户端HTML标记中读取这些设置的正确方法是什么?
What's the correct way to read these settings in the client side HTML markup ?
谢谢
推荐答案
除了使用<%= ConfigurationManager.AppSettings [MyAttribute]%>
,正如其他人所指出的,您也可以使用表达式构建器 。语法有点不同。您可以使用<%$ AppSettings:MyAttribute%>
来代替<%= ...%>
,如下所示:
In addition to using <%=ConfigurationManager.AppSettings["MyAttribute"]%>
, as others have noted, you can also use expression builders. The syntax is a little different. Instead of <%=...%>
you use <%$ AppSettings: MyAttribute %>
, like so:
<object id="myObjectID attr="<%$ AppSettings: MyAttribute %>" ...>
如果您只是将appSettings值直接转储到静态HTML中(正如我认为的那样在这个例子中,这两种方法是相同的。
If you are just dumping an appSettings value directly into static HTML (as I presume you are in this example), these two approaches are identical for all practical purposes.
然而,表达式构建器的好处在于您可以使用它们声明性地分配appSettings值到Web控件属性, 对<%= ...%>
语法所做的一切。也就是说,使用表达式构建器你可以这样做:
What is nice about expression builders, though, is that you can use them to declaratively assign appSettings values to Web control properties, something you cannot do with the <%=...%>
syntax. That is, with expression builders you can do something like:
<asp:Label runat="server" ... Text="<%$ AppSettings: MyAttribute %>" />
您可以不是做:
Whereas you could not do:
<asp:Label runat="server" ... Text="<%=ConfigurationManager.AppSettings["MyAttribute"]%>" />
这篇关于如何阅读HTML标记中的web.config APP密钥设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!