【问题标题】:ImageResizer throws 404 when no query parameters are present不存在查询参数时 ImageResizer 抛出 404
【发布时间】:2015-05-07 22:17:17
【问题描述】:

对于我的 MVC 4 站点,我使用 ImageResizer 来调整服务器端图像大小。我发现它是一个很棒的插件,但我遇到了一个小问题。

我通过 NuGet 工具安装了 ImageResizer,并自定义了 web.config 文件以使用 SqlReader 插件从我的 SQLDatabase 中检索图像 blob。我面临的问题是,当我在 url 中包含查询字符串时,可以很好地检索图像,但是当它只是图像名称和扩展名时,我从 IIS 收到 404 错误。

这会返回一个图像: ~/content/images/ef2dfaa8-5eb8-e411-827a-543530365cbe.jpg?w=100

这会返回一个 404 错误,详细信息如下: ~/content/images/ef2dfaa8-5eb8-e411-827a-543530365cbe.jpg

详细错误信息: 模块 IIS Web 核心 通知 MapRequestHandler 处理程序静态文件 错误代码 0x80070002 请求的 URL https://localhost:44300/content/images/ef2dfaa8-5eb8-e411-827a-543530365cbe.jpg 物理路径 E:\Work\website\website_site\website\website\content\images\ef2dfaa8-5eb8-e411-827a-543530365cbe.jpg 登录方法匿名 登录用户匿名 请求跟踪目录 C:\Users\Gabriël\Documents\IISExpress\TraceLogFiles\WEBSITE(6)

我已经研究过这个问题,唯一合乎逻辑的结论是它与虚拟路径的注册或访问它的特权有关。我不知道从这里去哪里。任何人都可以帮助引导我朝着正确的方向解决这个问题吗?

web.config 的配置部分如下所示

  <resizer>
<plugins>
  <add name="MvcRoutingShim" />
  <add name="SqlReader" 
       prefix="~/content/images/" 
       connectionString="ConnectionStringByName" 
       idType="UniqueIdentifier"
       blobQuery="SELECT FileData From ContentFiles WHERE Id=@id"
       modifiedQuery="SELECT UploadTime,UploadTime From ContentFiles WHERE Id=@id"
       existsQuery="SELECT COUNT(Id) From ContentFiles WHERE Id=@id"
       requireImageExtension="false"
       cacheUnmodifiedFiles="false" 
       extensionPartOfId="false" 
       checkForModifiedFiles="false" 
       vpp="true" 
       untrustedData="false" />
</plugins>

我在VS2012和IIS8.5上使用MVC4进行本地调试。

编辑:添加诊断页面 resizer.debug.ashx

> 
Image resizer diagnostic sheet      2015-03-02 05:23:52 PM

2 Issues detected:

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


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


You are using plugins from the Performance Edition: SqlReaderPlugin (Performance Edition)

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
ImageResizer.Plugins.SqlReader.SqlReaderPlugin

Configuration:

<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="SqlReader" prefix="~/content/images/" connectionString="[redacted]" idType="UniqueIdentifier" blobQuery="SELECT FileData From ContentFiles WHERE Id=@id" modifiedQuery="SELECT UploadTime,UploadTime From ContentFiles WHERE Id=@id" existsQuery="SELECT COUNT(Id) From ContentFiles WHERE Id=@id" requireImageExtension="false" cacheUnmodifiedFiles="false" extensionPartOfId="false" checkForModifiedFiles="false" vpp="true" untrustedData="false" />
</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 Microsoft-IIS/8.0 on Microsoft Windows NT 6.2.9200.0 and CLR 4.0.30319.34014
Trust level: Unrestricted
OS bitness: x86 !! Warning, running as 32-bit on a 64-bit OS(AMD64). This will limit ram usage !!
Executing assembly: C:\Program Files (x86)\IIS Express\iisexpress.exe
IntegratedPipeline: True

Loaded assemblies:

mscorlib                                 Assembly: 4.0.0.0         File: 4.0.30319.34014 Info: 4.0.30319.34014
System.Web                               Assembly: 4.0.0.0         File: 4.0.30319.34212 Info: 4.0.30319.34212
System                                   Assembly: 4.0.0.0         File: 4.0.30319.34239 Info: 4.0.30319.34239
System.Core                              Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Configuration                     Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Xml                               Assembly: 4.0.0.0         File: 4.0.30319.34230 Info: 4.0.30319.34230
System.Web.ApplicationServices           Assembly: 4.0.0.0         File: 4.0.30319.34212 Info: 4.0.30319.34212
System.Runtime.Caching                   Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
Microsoft.Build.Utilities.v4.0           Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Web.RegularExpressions            Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
Microsoft.JScript                        Assembly: 10.0.0.0        File: 12.0.20806.33440 Info: 12.0.20806.33440
System.Web.WebPages.Deployment           Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.WebPages                      Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
WebMatrix.WebData                        Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Web.WebPages.Deployment           Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Web.Optimization                  Assembly: 1.1.0.0         File: 1.1.40211.0    
System.Web.WebPages.Razor                Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
Microsoft.Web.Helpers                    Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Web.Mvc                           Assembly: 5.1.0.0         File: 5.1.20821.0     Info: 5.1.3-20821 (998d21fcdc6f99c6c039410608857cf8c1bd246f)
System.Web.WebPages.Deployment           Assembly: 2.0.0.0         File: 2.0.20710.0    
Microsoft.Web.WebPages.OAuth             Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
lotsonline                               Assembly: 1.0.0.0         File: 1.0.0.0        
Microsoft.VisualStudio.Web.PageInspector.Loader Assembly: 1.0.0.0         File: 1.3.41001.0    
Microsoft.Owin.Host.SystemWeb            Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.Owin                           Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.VisualStudio.Web.PageInspector.Runtime Assembly: 1.3.0.0         File: 1.3.41001.0    
System.Web.Razor                         Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
DotNetOpenAuth.Core                      Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
Mvc.Bootstrap.Datatables.MVC5            Assembly: 1.0.0.0         File: 1.0.0.0        
System.Data.Linq                         Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
Microsoft.Web.Infrastructure             Assembly: 1.0.0.0         File: 1.0.20105.407  
WebMatrix.Data                           Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
Microsoft.CSharp                         Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Data                              Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Web.Services                      Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Drawing                           Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.EnterpriseServices                Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.IdentityModel                     Assembly: 4.0.0.0         File: 4.0.30319.34230 Info: 4.0.30319.34230
System.Runtime.Serialization             Assembly: 4.0.0.0         File: 4.0.30319.34230 Info: 4.0.30319.34230
System.ServiceModel                      Assembly: 4.0.0.0         File: 4.0.30319.34230 Info: 4.0.30319.34230
System.ServiceModel.Activation           Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.ServiceModel.Web                  Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Activities                        Assembly: 4.0.0.0         File: 4.0.30319.34230 Info: 4.0.30319.34230
System.ServiceModel.Activities           Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.WorkflowServices                  Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Web.Extensions                    Assembly: 4.0.0.0         File: 4.0.30319.34212 Info: 4.0.30319.34212
System.Data.DataSetExtensions            Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Xml.Linq                          Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.ComponentModel.DataAnnotations    Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Web.DynamicData                   Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
Antlr3.Runtime                           Assembly: 3.5.0.2         File: 3.5.0.2        
DotNetOpenAuth.AspNet                    Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
DotNetOpenAuth                           Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
DotNetOpenAuth.OAuth.Consumer            Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
DotNetOpenAuth.OAuth                     Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
DotNetOpenAuth.OpenId                    Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
DotNetOpenAuth.OpenId.RelyingParty       Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
EntityFramework                          Assembly: 6.0.0.0         File: 6.1.30225.0     Info: 6.1.0-30225
EntityFramework.SqlServer                Assembly: 6.0.0.0         File: 6.1.30225.0     Info: 6.1.0-30225
Google.Apis.Auth                         Assembly: 1.8.2.23763    
Google.Apis.Auth.Mvc4                    Assembly: 1.8.2.23775    
Google.Apis.Auth.PlatformServices        Assembly: 1.8.2.23773    
Google.Apis.Core                         Assembly: 1.8.2.23761    
ImageResizer                             Assembly: 3.4.3.103       File: 3.4.3.103       Info: 3-4-3  Commit: bf92fd7
ImageResizer.Mvc                         Assembly: 3.4.3.103       File: 3.4.3.103       Info: 3-4-3  Commit: bf92fd7
ImageResizer.Plugins.DiskCache           Assembly: 3.4.3.103       File: 3.4.3.103       Info: 3-4-3  Commit: bf92fd7
ImageResizer.Plugins.SqlReader           Assembly: 3.4.3.103       File: 3.4.3.103       Info: 3-4-3  Commit: bf92fd7
Microsoft.AspNet.Identity.Core           Assembly: 2.0.0.0         File: 2.0.30423.0    
Microsoft.AspNet.Identity.EntityFramework Assembly: 2.0.0.0         File: 2.0.30423.0    
Microsoft.AspNet.Identity.Owin           Assembly: 2.0.0.0         File: 2.0.30423.0    
Microsoft.AspNet.SignalR.Core            Assembly: 2.1.1.0         File: 2.1.30724.119   Info: 2.1.1
Microsoft.AspNet.SignalR.Owin            Assembly: 1.2.1.0         File: 1.2.30210.0     Info: 1.2.1
Microsoft.AspNet.SignalR.SystemWeb       Assembly: 2.1.1.0         File: 2.1.30724.119   Info: 2.1.1
Microsoft.Data.Edm                       Assembly: 5.6.1.0         File: 5.6.1.61768     Info: 5.6.1.61768
Microsoft.Data.OData                     Assembly: 5.6.1.0         File: 5.6.1.61768     Info: 5.6.1.61768
Microsoft.Owin.Security.Cookies          Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.Owin.Security                  Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.Owin.Security.Facebook         Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.Owin.Security.Google           Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.Owin.Security.OAuth            Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.Owin.Security.Twitter          Assembly: 2.1.0.0         File: 2.1.30113.529   Info: 2.1.0
Microsoft.Threading.Tasks                Assembly: 1.0.12.0        File: 1.0.168.0       Info: 1.0.168.0
Microsoft.Threading.Tasks.Extensions.Desktop Assembly: 1.0.168.0       File: 1.0.168.0       Info: 1.0.168.0
Microsoft.Threading.Tasks.Extensions     Assembly: 1.0.12.0        File: 1.0.168.0       Info: 1.0.168.0
Microsoft.Web.Services3                  Assembly: 3.0.0.0         Info: 3.0.5305.0
Mono.Math                                Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
Newtonsoft.Json                          Assembly: 6.0.0.0         File: 6.0.3.17227    
Org.Mentalis.Security.Cryptography       Assembly: 4.3.0.0         File: 4.3.4.13329     Info: 4.3.4+build.13329.6de7bef5c3
Owin                                     Assembly: 1.0.0.0         File: 1.0            
Owin.Security.Providers                  Assembly: 1.4.4.0         File: 1.4.4.0        
Postal                                   Assembly: 0.9.2.0         File: 0.9.2.0        
System.Net.Http.Extensions               Assembly: 2.2.22.0        File: 2.2.22.0        Info: 2.2.22.0
System.Net.Http.Formatting               Assembly: 5.1.0.0         File: 5.1.20129.0     Info: 5.1.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Net.Http.Primitives               Assembly: 4.2.22.0        File: 4.2.22.0        Info: 4.2.22.0
System.Spatial                           Assembly: 5.6.1.0         File: 5.6.1.61768     Info: 5.6.1.61768
System.Web.Helpers                       Assembly: 3.0.0.0         File: 3.0.20129.0     Info: 3.0.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Web.Http                          Assembly: 5.1.0.0         File: 5.1.20129.0     Info: 5.1.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Web.Http.OData                    Assembly: 5.1.0.0         File: 5.1.20129.0     Info: 5.1.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Web.Http.Owin                     Assembly: 5.1.0.0         File: 5.1.20129.0     Info: 5.1.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
System.Web.Http.WebHost                  Assembly: 5.1.0.0         File: 5.1.20129.0     Info: 5.1.1-20129 (54866f0d3262d0fccfc2cb463f003459fcabd6c8)
WebGrease                                Assembly: 1.6.5135.21930 
Zlib.Portable                            Assembly: 1.9.1.9000      File: 1.9.1.9000     
System.Data.Entity                       Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Data.Services.Design              Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
App_global.asax.bo47o8hm                 Assembly: 0.0.0.0        
System.ServiceModel.Internals            Assembly: 4.0.0.0         File: 4.0.30319.34230 Info: 4.0.30319.34230
SMDiagnostics                            Assembly: 4.0.0.0         File: 4.0.30319.34230 Info: 4.0.30319.34230
System.Xaml.Hosting                      Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Xaml                              Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Net.Http                          Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Web.Routing                       Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Web.Abstractions                  Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Numerics                          Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Transactions                      Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Runtime                           Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Runtime.InteropServices           Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
Anonymously Hosted DynamicMethods Assembly Assembly: 0.0.0.0        
System.Net.Http.WebRequest               Assembly: 4.0.0.0         File: 4.0.30319.33440 Info: 4.0.30319.33440
System.Web.Mobile                        Assembly: 4.0.0.0         File: 4.0.30319.34212 Info: 4.0.30319.34212

The following plugin assemblies are loaded but do not seem to be in use. You should remove them (and especially their dependencies (unless used elsewhere)) from the /bin folder to improve application load times:

ImageResizer.Plugins.DiskCache           Assembly: 3.4.3.103       File: 3.4.3.103       Info: 3-4-3  Commit: bf92fd7

Reference list of plugin dependencies - so you know what additional dlls to remove when removing a plugin. (may not be up-to-date, see plugin docs):

The FreeImage plugin has the following dependencies: FreeImage.dll and FreeImageNET.dll
The Logging plugin depends on: NLog.dll
The AdvancedFilters, RedEye, and WhitespaceTrimmer plugins depend on: AForge.dll, AForge.Math.dll, and AForge.Imaging.dll
The PsdReader and PsdComposer plugins depend on: PsdFile.dll
The S3Reader plugin depends on: LitS3.dll
The BatchZipper plugin depends on: Ionic.Zip.Reduced.dll
The PdfRenderer plugin depends on gsdll32.dll or gdsll32.dll
The RedEye plugin depends on several dozen files... see the plugin docs.

【问题讨论】:

  • 你能发布诊断页面吗?您是否在 IIS 中安装了 StaticFileModule?是否启用了预编译?
  • StaticFileModule 已安装并且确实出现在 IIS 管理器的“模块”部分下。我不知道在哪里检查是否启用了预编译。我在执行之前编译了项目,它不是在预编译的代码上运行的。我还在帖子中附上了调试文件的输出

标签: asp.net-mvc imageresizer iis-8.5


【解决方案1】:

更改我的 web.config 文件条目

cacheUnmodifiedFiles="true" 

似乎可以解决问题。

【讨论】:

  • 听起来虚拟路径提供程序由于某种原因被忽略了。这只是一种解决方法,它强制所有内容在提供服务之前进入磁盘。检查预编译;它可能已启用。
【解决方案2】:

StaticFileHandlers 的行为在 .NET 4.0 中发生了变化;它们不再处理可通过 VirtualPathProvider 访问的请求。

恢复旧行为的解决方法 - 编辑 web.config:

<system.webServer>
    <handlers>
      <add name="StaticGifImages" path="*.gif" verb="*" type="System.Web.StaticFileHandler" />
      <add name="StaticPngImages" path="*.png" verb="*" type="System.Web.StaticFileHandler" />
      <add name="StaticJpgImages" path="*.jpg" verb="*" type="System.Web.StaticFileHandler" />
    </handlers>
  </system.webServer>

【讨论】:

    猜你喜欢
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    相关资源
    最近更新 更多