ASP.NET性能提升秘诀之管道与进程优化2011-11-22 IT168 罗江华ASP.NET 2.0中包涵了很多秘密,当你发现它时,可以为你的程序带来更大的性能和扩展性提升。例如 ,了解了在Membership和Profile provider提供程序中所隐藏的秘密瓶颈后就可以方便地的解决验证问题 并使得授权操作的速度加快。另外,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.NETFramework$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>