技术开发 频道

ASP.NET性能提升秘诀之管道与进程优化

  【IT168 专稿】ASP.NET 2.0中包涵了很多秘密,当你发现它时,可以为你的程序带来更大的性能和扩展性提升。例如,了解了在Membership和Profile provider提供程序中所隐藏的秘密瓶颈后就可以方便地的解决验证问题并使得授权操作的速度加快。

  第二篇:ASP.NET性能提升之站点部署与内容传输

  另外,ASP.NET HTTP管道为了避免针对每次请求所要执行的必要代码而发生阻塞。不仅那样,ASP.NET工作者进程能够推动其限制而获得更高的性能。页面碎片在浏览器端的输出缓存(不是在服务器端)可以显著节约回访者的下载时间。按需求的用户界面下载可以让你的站点给人快速流畅的感觉。

  最后内容传输网络和HTTP缓存头的恰当使用可以让你的网站惊人的快速。在这篇文章中,你将学习到这些技术,它能够使你的ASP.NET应用程序获得更高的性能、更好的扩展性 ,并且可以在任何ASP.NET的网站上实现,尤其是那些应用了ASP.NET 2.0 Membership 和Profile provider的站点。

  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目录下)。

<httpModules>
  
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
  
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
  
<add name="WindowsAuthentication"
        type
="System.Web.Security.WindowsAuthenticationModule" />
  
<add name="FormsAuthentication"
        type
="System.Web.Security.FormsAuthenticationModule" />
  
<add name="PassportAuthentication"
        type
="System.Web.Security.PassportAuthenticationModule" />
  
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
  
<add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
  
<add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule,
                             System.Web.Mobile, Version=1.0.5000.0,
                             Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
/>
</httpModules>

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

<httpModules>
        
<!-- Remove unnecessary Http Modules for faster pipeline -->
        
<remove name="Session" />
        
<remove name="WindowsAuthentication" />
        
<remove name="PassportAuthentication" />
        
<remove name="AnonymousIdentification" />
        
<remove name="UrlAuthorization" />
        
<remove name="FileAuthorization" />
</httpModules>

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

0
相关文章