Some changes to Web. config in ASP. net2.0

Source: Internet
Author: User
Tags stack trace connectionstrings

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.