IHttpHandlerFactory的使用測試
來源:互聯網
上載者:User
仿照msdn寫了一個接管http請求的類,對於aspx檔案,可以正常實現功能,但是對於圖片檔案,比如
*.jpg卻不行,找了一些資料也沒搞清楚,cs檔案和config檔案如下:
搞定了,在IIS中指定對.jpg檔案的映射
[D:WINDOWSMicrosoft.NETFrameworkv1.1.4322aspnet_isapi.dll]
HandlerFactory.cs
using System;
using System.Web;
namespace Handlers
{
class HandlerFactory : IHttpHandlerFactory
{
public IHttpHandler GetHandler(HttpContext context, string requestType, String url, String pathTranslated)
{
IHttpHandler handlerToReturn;
if("get" == context.Request.RequestType.ToLower())
{
handlerToReturn = new HandlerImg();
}
else if("post" == context.Request.RequestType.ToLower())
{
handlerToReturn = new HandlerImg();
}
else
{
handlerToReturn = null;
}
return handlerToReturn;
}
public void ReleaseHandler(IHttpHandler handler)
{
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class HandlerImg : IHttpHandler
{
public virtual void ProcessRequest(HttpContext context)
{