浅谈ASP.NET管道优化

ASP.NET管道优化

位于请求管道中的很多ASP.NET默认的HttpModules用于拦截客户端所发出的每个请求。例如,SessionStateModule拦截每个请求,并解析对应的会话cookie,然后在HttpContext中加载适当的会话。实时证明,并不是所有的modules都是必要的。

 

例如,如果你不使用Membership和Profile provider提供程序,那么你就可以不需要FormsAuthentication module。如果你需要为你的用户使用Windows验证,那么你就可以不需要WindowsAuthentication。位于管道中的这些 modules仅仅在每次请求到来时执行一些不必要的代码。

 

默认的modules都定义在了machine.config文件中(位于$WINDOWS$\Microsoft.NET\Framework\$VERSION$\CONFIG目录下)。

 

  1. <httpModules> 
  2. <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" /> 
  3. <add name="Session" type="System.Web.SessionState.SessionStateModule" /> 
  4. <add name="WindowsAuthentication" 
  5. type="System.Web.Security.WindowsAuthenticationModule" /> 
  6. <add name="FormsAuthentication" 
  7. type="System.Web.Security.FormsAuthenticationModule" /> 
  8. <add name="PassportAuthentication" 
  9. type="System.Web.Security.PassportAuthenticationModule" /> 
  10. <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" /> 
  11. <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" /> 
  12. <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule,  
  13. System.Web.Mobile, Version=1.0.5000.0,  
  14. Culture=neutralPublicKeyToken=b03f5f7f11d50a3a/> 
  15. </httpModules> 

你可以通过在站点的web.config文件中添加<remove>节点到你的网站应用程序中来删除这些默认的modules。ASP.NET管道优化代码例如:

 

  1. <httpModules> 
  2.  <!-- Remove unnecessary Http Modules for faster pipeline --> 
  3.  <remove name="Session" /> 
  4.  <remove name="WindowsAuthentication" /> 
  5.  <remove name="PassportAuthentication" /> 
  6.  <remove name="AnonymousIdentification" /> 
  7.  <remove name="UrlAuthorization" /> 
  8.  <remove name="FileAuthorization" /> 
  9. </httpModules> 

 上面的配置对于使用了数据库并基于Forms验证的网站来说非常适合,它们并不需要任何会话的支持。因此,所有这些modules都可以安全的删除。以上介绍ASP.NET管道优化

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值