Asp.net Configuration Part(1)

本文深入解析ASP.NET配置机制,包括Global.asax中的关键事件如ApplicationStart、ApplicationEnd等的作用及用法;阐述了不同级别的配置文件(Machine.config、Web.config)如何继承与应用;并介绍了如何通过Location标签设置特定路径的配置,以及如何创建和使用Section Class进行复杂配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值