经过几个小时的研究,我使用类(RouteHandler.cs)http处理程序完成了它,但没有使用.ashx,因为.ashx不能使用global.asax进行路由
public class RouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
HttpHanler httpHandler = new HttpHanler();
return httpHandler;
}
public class HttpHanler : IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
var routeValues = context.Request.RequestContext.RouteData.Values;
string file = context.Request.RequestContext.RouteData.Values["img"].ToString();
// anything you can do here.
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite("~/cat.jpg");
context.Response.End();
}
}
}
然后在 global.asax 中注册一条路线
routes.Add(new Route("Thumb/{img}", new RouteHandler()));