的研究我一直在使用類(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()));
傢伙,請建議我的東西.. –