`

浅谈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管道优化

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics