没有扩展名的ImageResizer和图像文件

时间:2013-01-17 20:31:20

标签: asp.net-mvc imageresizer

我在网络应用中一直使用ImageResizer.net,但现在我需要它来调整大小并提供没有(也不能)有文件扩展名的图像,如下所示:

http://localhost:58306/ClientImages/Batch/2012/12/10/f45198b7c452466684a4079de8d5f85f?width=600

在这种情况下,我知道我的文件总是TIFF,但是它们没有文件扩展名。

我有什么选择?

/resizer.debug.ashx:https://gist.github.com/raw/9c867823c983f0e5be10/4db31cb21af8b9b36f0aa4e765f6f459ba4b309f/gistfile1.txt

更新

我遵循了计算机语言学家的指示:

    protected void Application_Start()
    {
        Config.Current.Pipeline.PostAuthorizeRequestStart +=
            delegate
                {
                    var path = Config.Current.Pipeline.PreRewritePath;
                    var clientImgsRelPath = PathUtils.ResolveAppRelative("~/ClientImages/");
                    var isClientImageRequest = path.StartsWith(clientImgsRelPath, StringComparison.OrdinalIgnoreCase);

                    if (isClientImageRequest)
                        Config.Current.Pipeline.SkipFileTypeCheck = true;
                };


                // other app start code here
    }

http://localhost:58306/ClientImages/Batch/2012/12/10/92d67b45584144beb5f791aaaf760252?width=600只响应原始图片而没有调整大小。

这里也有人询问:http://imageresizing.net/docs/howto/cache-non-images#comment-571615564

在使用Cassini或Visual Studio Web服务器进行开发期间或您想要调用它时,会发生这种情况。

1 个答案:

答案 0 :(得分:2)

首先,您必须使用IIS7集成模式。经典模式不起作用;它不允许ASP.NET访问无扩展请求

除非您明确说明,否则ImageResizer无法知道无扩展名的网址是图片。

本文档解释:

http://imageresizing.net/docs/howto/cache-non-images

基本上,您最终会在URL上执行逻辑(通常是String.StartsWith),以确定ImageResizer是否应将文件视为图像。

Config.Current.Pipeline.PostAuthorizeRequestStart += delegate(IHttpModule sender, HttpContext context) {
  string path = Config.Current.Pipeline.PreRewritePath;

  //Skip the file extension check for everything in this folder:
  if (path.StartsWith(PathUtils.ResolveAppRelative("~/folder/of/images"), 
        StringComparison.OrdinalIgnoreCase)){

        Config.Current.Pipeline.SkipFileTypeCheck = true; 
  }
};

您应该在global.asax中的Application_Start中注册此事件处理程序。

相关问题