本文标签: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目录下) 。 - <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文件中添加节点到你的网站应用程序中来删除这些默认的modules 。ASP.NET管道优化代码例如:
- <httpModules>
-
- <remove name="Session" />
- <remove name="WindowsAuthentication" />
- <remove name="PassportAuthentication" />
- <remove name="AnonymousIdentification" />
- <remove name="UrlAuthorization" />
- <remove name="FileAuthorization" />
- httpModules>
上面的配置对于使用了数据库并基于Forms验证的网站来说非常适合,它们并不需要任何会话的支持 。因此,所有这些modules都可以安全的删除 。以上介绍ASP.NET管道优化
|