1 / 8

Расширение стандартных механизмов ASP.NET 4.0

Расширение стандартных механизмов ASP.NET 4.0. Андрей Веселов. Расширение механизмов ASP.NET. Собственный провайдер кэширования ; Расширение механизма контроля запросов ; Определение возможностей браузера ; Экранирование вывода данных. Провайдер кэширования.

porter
Download Presentation

Расширение стандартных механизмов ASP.NET 4.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Расширение стандартных механизмов ASP.NET 4.0 Андрей Веселов

  2. Расширение механизмов ASP.NET • Собственный провайдер кэширования; • Расширение механизма контроля запросов; • Определение возможностей браузера; • Экранирование вывода данных.

  3. Провайдер кэширования 1.Реализовать абстрактный класс OutputCacheProvider usingSystem.Web.Caching; public class CustomCacheProvider : OutputCacheProvider { public override object Add(string key, object entry, DateTimeutcExpiry) {} public override object Get(string key) { } public override void Remove(string key) { } public override void Set(string key, object entry, DateTimeutcExpiry) {} } 2.Указать используемый провайдер кэширования в web.config <configuration> <caching> <outputCachedefaultProvider="InMemoryCache"> <providers> <addname="InMemoryCache"type="Demo.InMemoryCacheProvider, Demo" /> </providers> </outputCache> </caching> </configuration>

  4. Контроль запросов 1.Реализовать абстрактный классRequestValidator usingSystem.Web.Util; public class CustomRequestValidator : RequestValidator { protected override boolIsValidRequestString( HttpContextcontext, stringvalue, RequestValidationSourcerequestValidationSource, stringcollectionKey, out intvalidationFailureIndex) { … } } 2.Указать используемую реализацию в web.config <configuration> <httpRuntimerequestValidationType="Demo.CustomRequestValidator, Demo" /> </configuration>

  5. Определение возможностей браузеров 1.Реализовать HttpCapabilitiesProvider usingSystem.Web.Configuration; public class CustomHttpCapabilitiesProvider: HttpCapabilitiesProvider { protected override HttpBrowserCapabilitiesGetBrowserCapabilities(HttpRequest request) { … } } 2.Указать используемый класс в web.config <configuration> <browserCapsprovider="Demo.CustomHttpCapabilitiesProvider, Demo" /> </configuration>

  6. Определение возможностей браузеров 1.Реализовать HttpCapabilitiesProviderили наследникаHttpCapabilitiesDefaultProvider usingSystem.Web. Configuration; public class CustomHttpCapabilitiesProvider: HttpCapabilitiesDefaultProvider { protected override HttpBrowserCapabilitiesGetBrowserCapabilities(HttpRequest request) { varbrowserCaps = base.GetBrowserCapabilities(request); // дополнительная логика определения возможностей браузера returnbrowserCaps; } } 2.Указать используемый класс в web.config <configuration> <browserCapsprovider="Demo.CustomHttpCapabilitiesProvider, Demo" /> </configuration>

  7. Экранирование вывода данных 1.Реализовать наследника классаHttpEncoder usingSystem.Web.HttpUtil; public class CustomHttpEncoder: HttpEncoder { protected override void HtmlEncode(string value, TextWriteroutput) { } protected override stringUrlPathEncode(string value) { } protected override byte[] UrlEncode(byte[] bytes, intoffset, intcount) { } protected override void HtmlDecode(string value, TextWriteroutput) { } protected override void HtmlAttributeEncode(string value, TextWriteroutput) { } protected override void HeaderNameValueEncode( stringheaderName, stringheaderValue, out string encodedHeaderName, out string encodedHeaderValue) { } } 2.Указать используемый класс в web.config <configuration> <httpRuntimeencoderType="Demo.CustomHttpEncoder, Demo" /> </configuration>

More Related