简体   繁体   English

IRouteHandler无法通过RouteConfig进行路由

[英]IRouteHandler not routing through RouteConfig

I have a IRouteHander class which I use to resize images on the fly and add expire headers to them, Recently I moved to MVC5 and now updating my code. 我有一个IRouteHander类,该类用于动态调整图像大小并向它们添加过期标头,最近我移到了MVC5,现在更新了我的代码。 I tried to register the same route for that class in RouteConfig.cs 我试图在RouteConfig.cs中为该类注册相同的路由

routes.Add(new Route("Image/{w}/{h}/{src}", new ThumbImageRouteHandler()));

but this route isn't working anymore like it was on MVC3 and giving 404 error in MVC5. 但是此路由不再像在MVC3上那样工作,并且在MVC5中给出404错误。 Is there anything I am missing here? 我在这里想念什么吗? this route leads to 这条路线导致

public class ThumbImageRouteHandler : 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)
                {
                //Do something
                }
               }
           }
}

Please help me fixing this issue. 请帮助我解决此问题。 Thanks 谢谢

After research I found out that I need to add a line in webconfig in order to make it work, here's how. 经过研究,我发现我需要在webconfig中添加一行以使其正常工作,这是方法。

  <system.webServer>
    <handlers>
      <add name="ApiURIs-ISAPI-Integrated-4.0-Image" path="/Image/*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>

Because IRouteHandler is generating re-sized images with a dynamic path, and IIS thinks this is the actual path to a directory because of dot(.) in the link and it thinks it's an extension, which is actually not. 因为IRouteHandler正在生成具有动态路径的调整大小的图像,并且IIS认为由于链接中的dot(。),所以这是目录的实际路径,并且它认为它是扩展名,但实际上不是。 So we have to add a handler in Web.Config to make it work. 因此,我们必须在Web.Config中添加一个处理程序以使其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM