After few hours of research I have done it using class (RouteHandler.cs) http handler but not with .ashx because .ashx can't be route using 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();
}
}
}
then in global.asax just register a route
routes.Add(new Route("Thumb/{img}", new RouteHandler()));