Wymagania: Dodano nowy moduł IHttpModule, który blokuje wszystkie żądania HTTP i liczy czas od początku do końca żądań, co ułatwia diagnostykę czasochłonnych stron oraz optymalizację i poprawę doświadczenia użytkownika.
W ASP.NET wiele z nich jest już zdefiniowanych z góryHttpModule, a nawet już zarejestrowany w profilu serwera, w folderze systemowymC:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.configZobacz zarejestrowany HttpModule w następujący sposób:
<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"/> <dodaj nazwę="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/> <dodaj nazwę="RoleManager" type="System.Web.Security.RoleManagerModule"/> <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/> <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/> <dodaj nazwę="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule"/> <add name="Profile" type="System.Web.Profile.ProfileModule"/> <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule"/> <add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </httpModules> Utworzenie nowego obiektu RequestTimeHttpModule, który dziedziczy interfejs IHttpModule, a kod wygląda następująco:
Nasz nowy moduł HttpModule również musi być skonfigurowany w web.config, w następujący sposób:
Spróbuj uzyskać dostęp do strony internetowej, renderowanie wygląda następująco:
ASP.NET moduły HTTP i obsługi HTTP:Logowanie do linku jest widoczne.
(Koniec)
|