1

在 Linux 的 Mono 上使用 ImageResizer 模块时出现以下错误:

Server Error in '/' Application

Argument is out of range. Parameter name: date

Description: HTTP 500. Error processing request.

Stack Trace:

System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: date
  at System.Web.HttpCachePolicy.SetLastModified (DateTime date) [0x00046] in /build/src/mono-2.10.8/mcs/class/System.Web/System.Web/HttpCachePolicy.cs:225 
  at ImageResizer.Caching.ResponseHeaders.DefaultApplyToResponseMethod (IResponseHeaders headers, System.Web.HttpContext context) [0x00000] in <filename unknown>:0 
  at ImageResizer.Plugins.Basic.NoCacheHandler.ProcessRequest (System.Web.HttpContext context) [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication+<Pipeline>c__Iterator6.MoveNext () [0x00dad] in /build/src/mono-2.10.8/mcs/class/System.Web/System.Web/HttpApplication.cs:1368 
  at System.Web.HttpApplication.Tick () [0x00000] in /build/src/mono-2.10.8/mcs/class/System.Web/System.Web/HttpApplication.cs:932 

Version information: Mono Runtime Version: 2.10.8 (tarball Sat Dec 31 02:07:23 UTC 2011); ASP.NET Version: 4.0.30319.1

这是调试表:

Image resizer diagnostic sheet      07/09/2012 14:15:41

3 Issues detected:

(Warning):  To potentially see additional errors here, perform an image resize request.


(Warning):  UrlAuthorizationModule.CheckUrlAccessForPrincipal is not supported on this runtime (are you running Mono?)
            It may be possible for users to bypass UrlAuthorization rules you have defined for your website, and access images that would otherwise be protected. If you do not use UrlAuthorization rules, this should not be a concern. You may also re-implement your security rules by handling the Config.Current.Pipeline.AuthorizeImage event.

(Warning):  NoCache is only for development usage, and cannot scale to production use.
            Add DiskCache or CloudFront for production use


You are not using any paid bundles.

Registered plugins:

ImageResizer.Plugins.Basic.DefaultEncoder
ImageResizer.Plugins.Basic.NoCache
ImageResizer.Plugins.Basic.ClientCache
ImageResizer.Plugins.Basic.Diagnostic
ImageResizer.Plugins.Basic.SizeLimiting
ImageResizer.Plugins.MvcRoutingShim.MvcRoutingShimPlugin

Configuration:

<resizer>
<pipeline fakeExtensions=".ashx" />
<plugins>
<add name="MvcRoutingShim" />
</plugins>
</resizer>


Accepted querystring keys:

quality, format, thumbnail, maxwidth, maxheight, width, height, w, h, scale, stretch, crop, cropxunits, cropyunits, page, bgcolor, rotate, flip, sourceFlip, sFlip, sRotate, borderWidth, borderColor, paddingWidth, paddingColor, ignoreicc, frame, useresizingpipeline, cache, process, margin, anchor, dpi, mode, zoom, 

Accepted file extensions:

bmp, gif, exif, png, tif, tiff, tff, jpg, jpeg, jpe, jif, jfif, jfi, 

Environment information:

Running Apache on Unix 2.6.39.2 and CLR 4.0.30319.1
Trust level: Unrestricted
OS bitness: 
Executing assembly: /usr/bin/mono
IntegratedPipeline: False

Loaded assemblies:

System.Runtime.Caching                   Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Messaging                         Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Transactions                      Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
Mono.Data.Tds                            Assembly: 4.0.0.0        
Mono.Security                            Assembly: 4.0.0.0        
System.Security                          Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
Mono.CSharp                              Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
App_global.asax_199cffe9                 Assembly: 0.0.0.0        
Microsoft.Web.Infrastructure             Assembly: 1.0.0.0         File: 1.0.20105.407  
dotless.Core                             Assembly: 1.3.0.3         File: 1.3.0.3         Info: 1.3.0.3
System.Web.WebPages.Razor                Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.WebPages.Deployment           Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.Razor                         Assembly: 1.0.0.0         File: 1.0.20105.407  
ImageResizer                             Assembly: 3.2.3.302       File: 3.2.3.302       Info: 3-2-beta-3  Commit: 245e873
ImageResizer.Mvc                         Assembly: 3.2.3.302       File: 3.2.3.302       Info: 3-2-beta-3  Commit: 245e873
System.Web.WebPages                      Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.Mvc                           Assembly: 3.0.0.0         File: 3.0.20105.0    
System.Web.Routing                       Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.Helpers                       Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.Abstractions                  Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.ApplicationServices           Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Data.Linq                         Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.DynamicData                   Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.ComponentModel.DataAnnotations    Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Xml.Linq                          Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Data.DataSetExtensions            Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.Extensions                    Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Core                              Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.ServiceModel.Web                  Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 3.5.594.0
System.ServiceModel                      Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Xaml                              Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Runtime.Serialization             Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.IdentityModel                     Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.EnterpriseServices                Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Drawing                           Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.Services                      Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Data                              Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
Microsoft.CSharp                         Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
Mono.Posix                               Assembly: 4.0.0.0        
Mono.WebServer2                          Assembly: 0.4.0.0        
mod-mono-server4                         Assembly: 2.10.2.0       
Mono.Web                                 Assembly: 4.0.0.0         Info: 0.0.0.1
System.Xml                               Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System                                   Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Configuration                     Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web                               Assembly: 4.0.0.0         File: 4.0.0.0         Info: 0.0.0.1
mscorlib                                 Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1

知道这里可能出了什么问题吗?

4

1 回答 1

1

这在技术上是 Mono 中的一个错误 - .NET 2.0 和 .NET 4.0 在执行转换之前都将日期转换为通用时间,而 mono 将其与本地服务器时间进行比较,甚至无法规范化这两个变量以确保它们具有匹配时间区。

单声道查看代码

        public void SetLastModified (DateTime date)
        {

            if (date > DateTime.Now)
                throw new ArgumentOutOfRangeException ("date");

            if (have_last_modified && date < last_modified)
                return;

            have_last_modified = true;
            last_modified = date;
        }

.NET(V2 和 V4)(使用 ILSpy,在加载了 System.Web 的情况下搜索 HttpCachePolicy)

或者,单击此链接以查看反汇编。

SetLastModified(DateTime 日期)的伪代码:

  1. 将日期转换为世界时间。
  2. 将日期时间向下舍入到最接近的 10,000,000 个刻度的倍数
  3. 验证该值是否小于 DateTime.UtcNow,如果不是,则抛出异常。
  4. 如果该值的本地副本之前已设置并且比该值“新”,则不要理会它。
  5. 否则,将值的本地副本设置为参数的通用时间版本。

调用代码(ImageResizer),/Core/Caching/ResponseHeaders.cs

        //Sets the Last-Modifed: header
        //The check against the current time is because  files served from another server may have a modified date in the future, if the clocks are not synchronized.
        //ASP.NET incorrectly blocks an future modified date from being sent, with an ArgumentOutOfRangeException
        DateTime utc = headers.LastModified.ToUniversalTime();

        if (utc != DateTime.MinValue && utc < DateTime.UtcNow) {
            context.Response.Cache.SetLastModified(utc);
        }

找到一个不会破坏某些东西的解决方法并不是很简单。MS SQL 在未指定的时区提供 LastModified 值,而文件系统提供 UTC,但如果它们来自远程服务器,则可以在未来提供。

由于传入的 DateTime 值通常不包含时区标志,因此标准化非常重要。

转换为 UTC、测试、转换回本地、测试、然后分配可能是一种有效的解决方法。

我建议编辑 /Core/Caching/ResponseHeaders.cs,方法 DefaultApplyToResponseMethod 使用以下语句

    if (utc != DateTime.MinValue && utc < DateTime.UtcNow && utc.ToLocalTime() < DateTime.Now) {
        context.Response.Cache.SetLastModified(utc.ToLocalTime());
    }

请让我看看您是否注意到逻辑上的缺陷;如果我对你有用并通过了 beta 测试,它可能会集成到未来的版本中。

于 2012-07-09T16:00:03.537 回答