ASP.NET: Auf ConnectionStrings und AppSettings der web.config zugreifen

web.config:

<appSettings>
  <add key="copyright" value="(c) 2004"/>
</appSettings>
<connectionStrings>
  <add name="mainDB" connectionString="..." providerName="..." />
</connectionStrings>

*.aspx.cs

using System.Configuration;
//...
string appCopy = ConfigurationManager.AppSettings["copyright"];
string appConn = ConfigurationManager.ConnectionStrings["mainDB"];

*.aspx:

<asp:Label ID="Label1" runat="server" Text="<%$ AppSettings:copyright %>" />

Übersicht über ASP.NET-Ausdrücke:
http://msdn.microsoft.com/de-de/library/d5bd1tad(VS.80).aspx

ASP.NET

September 2008 | Permalink | Feedback