Asp.net mvc 3 用于调整图像大小的MVC3通用处理程序(.ashx)(需要干净的URL)
我在asp.net mvc3 web应用程序中有一个通用处理程序(.ashx)。我用它来调整大小和缓存图像。但是我的Url不干净()我想让它像 我怎么做 我可以在global.asax中映射路线吗?是的,然后如何?还是应该使用IIS 7 URL重写Asp.net mvc 3 用于调整图像大小的MVC3通用处理程序(.ashx)(需要干净的URL),asp.net-mvc-3,url-rewriting,httpcontext,generic-handler,Asp.net Mvc 3,Url Rewriting,Httpcontext,Generic Handler,我在asp.net mvc3 web应用程序中有一个通用处理程序(.ashx)。我用它来调整大小和缓存图像。但是我的Url不干净()我想让它像 我怎么做 我可以在global.asax中映射路线吗?是的,然后如何?还是应该使用IIS 7 URL重写 非常感谢您的帮助,谢谢经过几个小时的研究,我已经使用class(RouteHandler.cs)http处理程序完成了,但没有使用.ashx,因为.ashx不能使用global.asax进行路由 public class RouteHandler :
非常感谢您的帮助,谢谢经过几个小时的研究,我已经使用class(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()));
伙计们,请给我提个建议。。