C# Класс NCombo.BaseHttpHandler

An abstract base Http Handler for all your IHttpHandler needs.

For the most part, classes that inherit from this class do not need to override ProcessRequest. Instead implement the abstract methods and properties and put the main business logic in the HandleRequest.

HandleRequest should respond with a StatusCode of 200 if everything goes well, otherwise use one of the various "Respond" methods to generate an appropriate response code. Or use the HttpStatusCode enumeration if none of these apply.

Courtesy of Phil Haack: http://haacked.com/archive/2005/03/17/AnAbstractBoilerplateHttpHandler.aspx

Updated to use HttpContextBase for better testability, inspired by Kazi Manzur: http://weblogs.asp.net/rashid/archive/2009/03/12/unit-testable-httpmodule-and-httphandler.aspx

Наследование: IHttpHandler
Показать файл Открыть проект

Открытые методы

Метод Описание
BaseHttpHandler ( ) : System

Creates a new BaseHttpHandler instance.

HandleRequest ( System.Web.HttpContextBase context ) : void

Handles the request. This is where you put your business logic.

This method should result in a call to one (or more) of the following methods:

context.Response.BinaryWrite();

context.Response.Write();

context.Response.WriteFile();

someStream.Save(context.Response.OutputStream);

etc...

If you want a download box to show up with a pre-populated filename, add this call here (supplying a real filename).

Response.AddHeader("Content-Disposition" , "attachment; filename=\"" + Filename + "\"");

ProcessRequest ( HttpContext context ) : void

Processs the incoming HTTP request.

SetResponseCachePolicy ( HttpCachePolicyBase cache ) : void

Sets the cache policy. Unless a handler overrides this method, handlers will not allow a respons to be cached.

ValidateParameters ( HttpContextBase context ) : bool

Validates the parameters. Inheriting classes must implement this and return true if the parameters are valid, otherwise false.

Защищенные методы

Метод Описание
Init ( System.Web.HttpContextBase context ) : void

Code which is necessary to initialize this instance.

RespondFileNotFound ( HttpContextBase context ) : void

Helper method used to Respond to the request that the file was not found.

RespondForbidden ( HttpContextBase context ) : void

Helper method used to Respond to the request that the request in attempting to access a resource that the user does not have access to.

RespondInternalError ( HttpContextBase context ) : void

Helper method used to Respond to the request that an error occurred in processing the request.

Описание методов

BaseHttpHandler() публичный Метод

Creates a new BaseHttpHandler instance.
public BaseHttpHandler ( ) : System
Результат System

HandleRequest() публичный абстрактный Метод

Handles the request. This is where you put your business logic.

This method should result in a call to one (or more) of the following methods:

context.Response.BinaryWrite();

context.Response.Write();

context.Response.WriteFile();

someStream.Save(context.Response.OutputStream);

etc...

If you want a download box to show up with a pre-populated filename, add this call here (supplying a real filename).

Response.AddHeader("Content-Disposition" , "attachment; filename=\"" + Filename + "\"");

public abstract HandleRequest ( System.Web.HttpContextBase context ) : void
context System.Web.HttpContextBase Context.
Результат void

Init() защищенный абстрактный Метод

Code which is necessary to initialize this instance.
protected abstract Init ( System.Web.HttpContextBase context ) : void
context System.Web.HttpContextBase
Результат void

ProcessRequest() публичный Метод

Processs the incoming HTTP request.
public ProcessRequest ( HttpContext context ) : void
context System.Web.HttpContext Context.
Результат void

RespondFileNotFound() защищенный Метод

Helper method used to Respond to the request that the file was not found.
protected RespondFileNotFound ( HttpContextBase context ) : void
context HttpContextBase Context.
Результат void

RespondForbidden() защищенный Метод

Helper method used to Respond to the request that the request in attempting to access a resource that the user does not have access to.
protected RespondForbidden ( HttpContextBase context ) : void
context HttpContextBase Context.
Результат void

RespondInternalError() защищенный Метод

Helper method used to Respond to the request that an error occurred in processing the request.
protected RespondInternalError ( HttpContextBase context ) : void
context HttpContextBase Context.
Результат void

SetResponseCachePolicy() публичный Метод

Sets the cache policy. Unless a handler overrides this method, handlers will not allow a respons to be cached.
public SetResponseCachePolicy ( HttpCachePolicyBase cache ) : void
cache HttpCachePolicyBase Cache.
Результат void

ValidateParameters() публичный абстрактный Метод

Validates the parameters. Inheriting classes must implement this and return true if the parameters are valid, otherwise false.
public abstract ValidateParameters ( HttpContextBase context ) : bool
context HttpContextBase Context.
Результат bool