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 はそれをローカル サーバー時間と比較し、2 つの変数を正規化して時刻が一致することを確認することさえできません。ゾーン。

モノコードを参照

        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 date) の疑似コード:

  1. 日付を世界時に変換します。
  2. datetime を 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());
    }

ロジックに欠陥があるかどうかを確認させてください。うまく機能し、ベータ テストに合格した場合、将来のリリースに統合される可能性があります。

于 2012-07-09T16:00:03.537 に答える