首页 > 解决方案 > 启用 TinyCache 插件后 ImageResizer 不再工作

问题描述

我正在尝试让 ImageResizer 与 TinyCache 插件一起使用。(我将使用 ImageResizer Essential Edition)。

我在集成模式的 Windows 10 / IIS 10.0 下

我有一个 。安装了以下NuGet 包的net webform 4.7.2网站:

我的web.config如下:

<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
    <!--<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />-->
    <section name="resizer" type="ImageResizer.ResizerSection,ImageResizer"  requirePermission="false"  />
</configSections>
<!--check URL ~/resizer.debug.ashx-->
<resizer>
    <!--Unless you (a) use Integrated mode, or (b) map all requests to ASP.NET, 
        you'll need to add .ashx to your image URLs: image.jpg.ashx?width=200&height=20 

        Using IIS7 Integrated mode or the Visual Studio web server? You can skip this step. 
        You also don't need to do this if you are using the .jpg.ashx syntax.-->

    <pipeline fakeExtensions=".ashx" defaultCommands="autorotate.default=true" />

    <plugins>
    <add name="TinyCache" />
    <!--<add name="VirtualFolder" virtualPath="~/" physicalPath="..\Assets" vpp="false "/>-->
    <!--<add name="VirtualFolder" virtualPath="~/" physicalPath="../Assets" vpp="false "/>-->
    </plugins>
</resizer>
<system.web>
    <customErrors defaultRedirect="YourErrorPage.aspx"
                mode="RemoteOnly">
    </customErrors>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
    <pages>
    <namespaces>
        <add namespace="System.Web.Optimization" />
    </namespaces>
    <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
    </controls>
    </pages>
    <httpModules>
    <!-- This is for IIS7/8 Classic Mode and Cassini-->
    <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </httpModules>
</system.web>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
    </dependentAssembly>
    </assemblyBinding>
</runtime>
<system.codedom>
    <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
</system.codedom>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
    <!--This is for IIS7+ Integrated mode-->
    <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </modules>
</system.webServer>
</configuration>

当我禁用 TinyCache 插件(只需注释该<add name="TinyCache" />行)时,它在我尝试调用图像来调整大小时起作用(例如 http:///Assets/TestImage.jpg?height=100 ;图像被调整大小;这里我有一个 TestImage我网站根目录Assets文件夹中的.jpg图片)

但是,我在诊断页面 http:///resizer.debug.ashx 上收到警告,表明我应该启用缓存: (Warning): NoCache is only for development usage, and cannot scale to production use.

所以我在 web.config 中启用了 TinyCache 插件。

然后我在诊断页面 http:///resizer.debug.ashx 上收到一条警告,我无法摆脱它:(Warning): To potentially see additional errors here, perform an image resize request.

如果我然后尝试调整图片大小(例如 http:///Assets/TestImage.jpg?height=100 .... 或事件(例如 http:///Assets/TestImage.jpg.ashx?height=100 我在我的情况下不需要 Win10 - IIS 10 集成模式)我收到以下错误: 调用 http://<myServer>/Assets/Porte.jpg?height=100 时出错

注意:这个错误的英文版本(我是法语)将是

无法找到该资源。

说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。

值得注意的是,文件 /App_Data/tiny_cache.cache 从未创建!(但是,我已将此文件夹的所有权限授予运行 IIS 池的用户......以及我的 DEV 框上的所有用户!)

如果您有任何想法/解决方案,请提前非常感谢!

我正在考虑使用https://imageprocessor.org/而不是 ImageResizer 因为没有任何痛苦:)

标签: c#imageresizer

解决方案


您需要安装protobuf-net nuget 包。因为缺少 dll,所以会抛出 FileNotFound 异常,进而转换为 404 错误。


推荐阅读