当没有查询参数时,ImageResizer会抛出404

时间:2015-03-02 16:35:17

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

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

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

这会返回一张图片: 〜/内容/图像/ ef2dfaa8-5eb8-e411-827a-543530365cbe.jpg?W = 100

这将返回404错误,其详细信息如下: 〜/内容/图像/ ef2dfaa8-5eb8-e411-827a-543530365cbe.jpg

  

详细错误信息:   模块IIS Web核心   通知MapRequestHandler   处理程序StaticFile   错误代码0x80070002   请求的网址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.

2 个答案:

答案 0 :(得分:0)

更改我的web.config文件条目

cacheUnmodifiedFiles="true" 

似乎可以解决问题。

答案 1 :(得分:0)

在.NET 4.0中,StaticFileHandlers的行为已发生变化;它们不再处理可通过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>