服务热线
153 8323 9821
web.config是以xml文件规范存储网站配置信息的载体,这一点跟应用程序配置文件app.config一样.
这个配置文件可以方便为我们存储一些网站配置信息,如网站数据库连接字符串,错误页面等
<configuration>
跟元素,其他节点都在它的内部
跟元素内部包含
<configSections>
配置节处理声明,指定配置节和命名空间的声明。通常,我们要载入第三方框架的时候会用到,如Log4net(日志),DCWeb(Gzip压缩),UrlRewriter(URL重写)
例子:
1
2
3
4
|
< configSections > <!-- 声明名称为log4net的类型为log4net.Config.Log4NetConfigurationSectionHandler命名空间为log4net的类 --> < section name = "log4net" type = "log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> </ configSections > |
<appSettings>
包含自定义应用程序设置,存储在文件中的任何信息。
例子:
1
2
3
4
|
< appSettings > <!-- 键为DefaultPhoto 值为/inc/ceshipic.jpg --> < add key = "DefaultPhoto" value = "/inc/ceshipic.jpg" /> </ appSettings > |
<connectionStrings>
为网站指定数据库连接字符串(名称/值对的形式)的集合。
例子:
1
2
3
4
|
< connectionStrings > <!-- 名称为constr的数据库连接 --> < add name = "constr" connectionString = "Data Source=.;uid=sa;pwd=1234;Initial Catalog=test_db" providerName = "System.Data.Client" /> </ connectionStrings > |
<system.web>
配置网站的行为方式,内部包括了asp.net网站的所有配置信息
子节点包括
<customErrors>错误信息配置
例子:
1
2
3
4
5
6
7
|
<!-- 错误节点,模式RemoteOnly defaultRedirect默认跳转页面 --> < customErrors mode = "RemoteOnly" defaultRedirect = "error.htm" > <!-- 错误信息500 跳转error.htm页面 --> < error statusCode = "500" redirect = "error.htm" /> <!-- 错误信息404 跳转nopage.htm页面 -->
相关文章
|