Using System;
Using System. Data;
Using System. configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. Web. configuration;
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
}
Protected Void Showmessage ( String Temp)
{
This. Response. Write ("<SCRIPT> alert ('" +Temp+ "') </SCRIPT>");
}
// Obtain the value of receivetting.
Protected Void Get_appsetting_click ( Object Sender, eventargs E)
{
StringMessage=System. Web. configuration. webconfigurationmanager. appsettings ["Message"];
This. Showmessage (Message );
}
// Obtains the value of the join string.
Protected Void Get_connection_click ( Object Sender, eventargs E)
{
StringCNN=System. Web. configuration. webconfigurationmanager. connectionstrings ["CNN"]. Connectionstring;
This. Showmessage (CNN );
}
// Use XPath to obtain a section in config
Protected Void Get_section_click ( Object Sender, eventargs E)
{
Configuration config;
Config = Webconfigurationmanager. openwebconfiguration ( " ~ " );
System. Web. configuration. identitysection section;
Section = Config. getsection ( " System. Web/identity " ) As System. Web. configuration. identitysection;
If (Section ! = Null )
{
Showmessage (section. Impersonate. tostring ());
}
}
// Change node Information
Protected Void Change_section_click ( Object Sender, eventargs E)
{
Configuration config;
Config = Webconfigurationmanager. openmachineconfiguration ( " ~ " );
System. Web. configuration. identitysection section;
Section = Config. getsection ( " System. Web/identity " ) As System. Web. configuration. identitysection;
If (Section ! = Null )
{
Section. Impersonate= !Section. Impersonate;
Config. Save ();
Showmessage ("Debug setting is now" +Section. Impersonate. tostring ());
}
}
// Obtain external data
Protected Void Get_external_click ( Object Sender, eventargs E)
{
StringCNN=System. Web. configuration. webconfigurationmanager. connectionstrings ["CNN"]. Connectionstring;
This. Showmessage (CNN );
}
}
CNN. config<Connectionstrings>
<AddName= "CNN"Connectionstring= "Cnnvalue"/>
</Connectionstrings>
Web. config <? XML version = "1.0" ?>
<! --
Note: As an alternative to hand editing this file you can use
Web Admin Tool to configure settings for your application. Use
The website-> ASP. NET configuration option in Visual Studio.
A full list of settings and comments can be found in
Machine. config. Comments usually located in
\ Windows \ Microsoft. NET \ framework \ v2.x \ config
-->
< Configuration Xmlns = "Http://schemas.microsoft.com/.NetConfiguration/v2.0" >
< Appsettings >
< Add Key = "Message" Value = "Hello World" />
</ Appsettings >
< Connectionstrings Configsource = "CNN. config" >
</ Connectionstrings >
< System . Web >
<! --
Set compilation DEBUG = "true" to insert debugging
Symbols into the compiled page. Because this
Affects performance, set this value to true only
During development.
-->
< Compilation Debug = "True" />
<! --
The <authentication> section enables Configuration
Of the Security Authentication mode used
ASP. NET to identify an incoming user.
-->
< Authentication Mode = "Windows" />
< Identity Impersonate = "True" />
<! --
The <customerrors> section enables Configuration
Of what to do if/when an unhandled error occurs
During the execution of a request. Specifically,
It enables developers to configure HTML error pages
To be displayed in place of a error stack trace.
<Customerrors mode = "remoteonly" defaultredirect = "genericerrorpage.htm">
<Error statuscode = "403" Redirect = "noaccess.htm"/>
<Error statuscode = "404" Redirect = "filenotfound.htm"/>
</Customerrors>
-->
</ System. Web >
</ Configuration >
For details, see this ....
Http://odetocode.com/Articles/418.aspx