【问题标题】:ImageResizer and image files without an extensionImageResizer 和没有扩展名的图像文件
【发布时间】:2013-01-17 20:31:20
【问题描述】:

我一直在我们的网络应用程序中使用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 服务器或任何您想称呼它的开发过程中。

【问题讨论】:

    标签: asp.net-mvc imageresizer


    【解决方案1】:

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

    ImageResizer 无法知道无扩展名的 URL 是图像,除非您明确告诉它。

    本文档解释:

    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 中注册此事件处理程序。

    【讨论】:

    • 您是否尝试过指定&process=always 来强制处理为图像?
    猜你喜欢
    • 2012-10-16
    • 1970-01-01
    • 2016-06-28
    • 2011-10-27
    • 1970-01-01
    • 2016-12-24
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    相关资源
    最近更新 更多