淺談ASP.NET管道優(yōu)化
ASP.NET管道優(yōu)化
位于請求管道中的很多ASP.NET默認(rèn)的HttpModules用于攔截客戶端所發(fā)出的每個請求。例如,SessionStateModule攔截每個請求,并解析對應(yīng)的會話cookie,然后在HttpContext中加載適當(dāng)?shù)臅?。實時證明,并不是所有的modules都是必要的。
例如,如果你不使用Membership和Profile provider提供程序,那么你就可以不需要FormsAuthentication module。如果你需要為你的用戶使用Windows驗證,那么你就可以不需要WindowsAuthentication。位于管道中的這些 modules僅僅在每次請求到來時執(zhí)行一些不必要的代碼。
默認(rèn)的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>節(jié)點到你的網(wǎng)站應(yīng)用程序中來刪除這些默認(rèn)的modules。ASP.NET管道優(yōu)化代碼例如:
- <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>
上面的配置對于使用了數(shù)據(jù)庫并基于Forms驗證的網(wǎng)站來說非常適合,它們并不需要任何會話的支持。因此,所有這些modules都可以安全的刪除。以上介紹ASP.NET管道優(yōu)化
【編輯推薦】