Web.config 可配置的数据

1.compilation:用来配置 ASP.NET 要编译 Web 应用程序。

1 <compilation debug="true"          //是否调试
2     optimizeCompilations="true"    //是否重新编译   默认false
3     targetFramework="4.0" />       // 指定.NET Framework版本 
View Code

2.自定义错误

model : 指定是启用还是禁用自定义错误 ,mode="On|Off|RemoteOnly"  启用|禁用|默认值。

<customErrors mode="RemoteOnly"     //是否启用和禁用
    defaultRedirect="GenericErrorPage.htm">   //出错时将浏览器定向到的默认 URL
  <error statusCode="403" redirect="NoAccess.htm" />//403错误显示页面
  <error statusCode="404" redirect="FileNotFound.htm" />//404错误显示页面
</customErrors>
View Code

3.身份验证和角色

mode:指定应用程序的默认身份验证模式。  mode="[Windows|Forms|Passport|None]"   window身份验证|窗体身份验证|默认身份验证|无需身份验证
<authentication mode="Windows"/>
View Code

4.system.webServer   只适用于 IIS 7.0 集成模式,而不适用于经典模式。具体而言,如果应用程序正在经典模式下运行,则会忽略 Web.config 文件的 system.WebServer 节中指定的所有托管代码模块和处理程序。与 IIS 的早期版本相同,托管代码模块和处理程序必须在 system.web 节的 httpModules 和 httpHandlers 元素中定义。

system.webServer 节的三个常见配置任务:

      1)  添加默认文件,以便在请求 URL 未包含特定的文件时,提供该默认文件。

<configuration>
  <system.webServer>
    <defaultDocument>
       <files>
           <add value="Products.aspx" /> 
        </files>   
     </defaultDocument>
  </system.webServer>
</configuration>                 
View Code

  2) 注册托管代码:每次请求时都会调用托管代码模块,通过该模块可对请求或响应进行自定义。

<configuration>
  <system.webServer>
    <modules>
      <add name="CustomModule" type="Samples.CustomModule" 
           precondition="managedHandler" />
    </modules>
//此前置条件会导致仅在请求 ASP.NET 应用程序资源(例如 .aspx 文件或托管处理程序)时才调用该模块。该资源中不包括静态文件(例如 .htm 文件)。
    <defaultDocument>
      <files>
        <add value="Products.aspx" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>
View Code

  3) 配置自定义响应标头

//实际的名称和类型将取决于该标头在应用程序中的功能。下面的示例演示如何添加名为 CustomHeader 且值为 CustomHeader 的自定义标头。
<configuration>
  <system.webServer>
    <httpProtocol>      <customHeaders>        <add name="CustomHeader" value="CustomHeader" />      <customHeaders>    </httpProtocol>
  </system.webServer>
</configuration>
View Code

 

转载于:https://www.cnblogs.com/bkpengqing/p/7660047.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值