一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

IHttpHandlerFactory的使用测试

时间:2008-01-18 编辑:简简单单 来源:一聚教程网

 
仿照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)
    {

热门栏目