当前位置:编程学习 > asp >>

IHttpHandlerFactory的使用测试

 
仿照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)
    {
补充:asp教程,高级应用
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,