62,074
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
namespace Web1
{
/// <summary>
/// JpgHandler 的摘要说明
/// </summary>
public class JpgHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string path = context.Request.PhysicalPath;
string serverHost = context.Request.Url.Host;
Uri u = context.Request.UrlReferrer;
context.Response.ContentType = "image/jpeg";
if (path.IndexOf("24.jpg")<=0)
{
path = context.Server.MapPath("~/Images/error.jpg");
context.Response.WriteFile(path);
}
else
{
path = context.Server.MapPath(context.Request.RawUrl);
context.Response.WriteFile(path);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
配置文件
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.jpg" type="Web1.JpgHandler,Web1"/>
</httpHandlers>
<compilation debug="true"/>
</system.web>
</configuration>