Asp.net Configuration Part(1)

2834 ワード

Asp.netConfiguration

Global asax


Common Events :


Application Start


Initializesome resource of application

Application End


Clean upresource

Application Error


Go tounexpected error Page

Application Dispose


Clean up

Session Start


Userspecific data initialize

Session End


Userspecific data finalize

Machine Config

<MachineKeyvalidationKey = “specific Value” Decryption Key=”specific Value” />

· Validation key is using for encryptview state
· for web Garden and web farm ,need toset as specific value, for saving view state value during post back.

Web Config


Configuration can be inheritance


For Http://localhost/A/B/C/MyPage.aspx
IIS will apply :
MachineConfig -> web Config -> A folder Web Config -> B Folder Web Config->C folder Web Config

Location


When wantto set more than 1 group of settings for different path , can use location tag
<Locationpath=”” >put this path specific settings</location>

Section class


Create a Section Class

ClassOrderService : ConfigurationSection {

[ConfigurationProperty(“available”,IsRequired…)]

Publicstring Available{get;set;}

}

Configuration

<Configuration>

<ConfigSections>

<sectionname=”OrderService” />

</ConfigSections>

</Configuration>

<OrderServiceavailable = “true” …other attributes/>

…

<System.Web></System.Web>

Use

OrderServicesection = (OrderService)ConfigurationManager.GetSection(“OrderService”);

varavailable = section.Available;

For Nested Configuration


Configuration

<Configuration>

<ConfigSections>

<sectionname=”OrderService” />

</ConfigSections>

</Configuration>

 

 

…

<System.Web></System.Web>

Create Section Class

ClassOrderService :ConfigurationSection {

[ConfigurationProperty(“location”,IsRequired=true)]

PublicLocation location{get;set;} 

}

ClassLocation : ConfigurationElement{

…

} 

Use :

Lbl.Text =section.location.ComputerName ;

Configuration section canbe encrypted


WAT


Web SiteAdministration tool
VS->Website->Asp.net Config