Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read web.config APP key settings in HTML markup

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.

I would like to place the parameters in my web.config with app settings "key/value" pairs.

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.

What's the correct way to read these settings in the client side HTML markup ?

Thanks

like image 339
Khalid Rahaman Avatar asked Oct 30 '10 01:10

Khalid Rahaman


People also ask

What is the app setting section in the web config file?

The <appSettings> element stores custom application configuration information, such as database connection strings, file paths, XML Web service URLs, or any other custom configuration information for an application.

Which settings are stored in web config file?

A configuration file (web. config) is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. In this way you can configure settings independently from your code.

What is app config and web config?

Web. Config is used for asp.net web projects / web services. App.Config is used for Windows Forms, Windows Services, Console Apps and WPF applications.


1 Answers

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

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.

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"]%>" />
like image 182
Scott Mitchell Avatar answered Sep 20 '22 06:09

Scott Mitchell