what's this <%$ AppSettings:something %> means

  • Thread starter Thread starter Osamede Zhang
  • Start date Start date
O

Osamede Zhang

I just can't understand what appSettings
means, how it work
thanks for your read
osamede
 
Osamede Zhang said:
I just can't understand what appSettings
means, how it work

It refers to a setting in the AppSettings section in the web.config file.
something refers to the name of the setting.
The entire expression is replaced by the value of the setting when the page
is run.

Riki
 
As Riki explained, but to add - its also bad practice as app settings is a
collection which used like this has to be iterated in its entirety to get
that specific value from the file every time. For performance it would be
better if this was read at application start once and stored in the
application object for use each time.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
 
re:
!>I just can't understand what appSettings

It means just what its name implies.

It's a designated repository for application configuration information which is used
in the app, like database connection strings, file paths, XML Web service URLs, etc.

Here's examples of multiple ways to use appSettings :

http://www.codeproject.com/dotnet/namevaluemultiple.asp

http://www.odetocode.com/Articles/345.aspx

http://www.codeproject.com/dotnet/EnhancedAppSettings.asp

http://msdn2.microsoft.com/en-us/library/aa903313(VS.71).aspx




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Thanks for your reply,it's very useful,
But how <%$ AppSettings:something %> is working? which class is really used
to read the file?
 
re:
!> But how <%$ AppSettings:something %> is working?
!> which class is really used to read the file?

You don't need a specific class.
The $ syntax is built into the Configuration Manager workspace.

$, in this context, means *evaluate* the applicable section of web.config.

If you have :
<appSettings>
<add key="selectDocs" value="SELECT * FROM documents WHERE thereisdata ORDERBY CreationDate DESC"/>
</appSettings>

You can retrieve the value of that query with :

<asp:Literal runat="server" Text="<%$ AppSettings:selectDocs%>" /><br/>

If you have:
<connectionStrings>
<add name="NwindConn"
connectionString="server=(local);trusted_connection=true;database=northwind"
providerName="System.Data.SqlClient" />
</connectionStrings>

You can retrieve the value of that query with :

<asp:Literal runat="server" Text="<%$ ConnectionStrings:NwindConn%>" />

Of course, you could also transfer those values to text variables and use them in other forms.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Back
Top