Asp.net Configuration Part(1)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
.NET Configuration 配置系统是用于管理和配置.NET应用程序的一套工具和机制。它允许开发人员在应用程序中定义和修改各种设置,以满足特定的需求。 配置系统的核心是配置文件,其中最重要的是Machine.config和应用程序的Web.config或App.config文件。Machine.config是计算机范围内的配置文件,而Web.config或App.config是应用程序范围内的配置文件。 配置文件使用XML格式,并包含各种元素和属性,用于定义应用程序的设置。其中,<configuration>元素是配置文件的根元素,它包含了整个配置的内容。 配置文件中的<configuration>元素可以包含多个<appSettings>元素,用于定义应用程序的键值对设置。例如: ```xml <configuration> <appSettings> <add key="Setting1" value="Value1" /> <add key="Setting2" value="Value2" /> </appSettings> </configuration> ``` 除了<appSettings>元素,配置文件还可以包含其他元素,如<connectionStrings>用于定义数据库连接字符串,<system.web>用于配置ASP.NET应用程序等。 通过使用配置系统,开发人员可以轻松地修改应用程序的设置,而无需重新编译代码。这使得应用程序更加灵活和可配置。 需要注意的是,配置文件的优先级是从高到低的,即应用程序级别的配置文件会覆盖计算机级别的配置文件。因此,可以根据需要在不同的配置文件中定义不同的设置。 总结起来,.NET Configuration 配置系统是一个强大的工具,用于管理和配置.NET应用程序的各种设置。通过配置文件,开发人员可以轻松地修改应用程序的设置,以满足特定的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值