【问题标题】:Configuring ImageResizer Web.config To Only Work On Certain Directories将 ImageResizer Web.config 配置为仅在某些目录上工作
【发布时间】:2015-10-30 16:31:01
【问题描述】:

产品使用:来自http://imageresizing.net的ImageResizer.dll

我有一个客户网站,我使用该产品为他们的在线购物车动态调整图像大小。该产品效果很好!我最近添加了一个自定义 HTTPHandler (MyCustomSecurityHandler) 来控制对特定目录中需要保护的图像的访问。只要我不尝试使用 ImageResizer 识别的 QueryString 参数“width”或“height”访问图像,MyCustomSecurityHandler 的代码就可以正常工作。如果没有使用 QueryString 参数,ImageResizer 会忽略请求,而我的 Custom HTTPHandler 会接收请求并完美处理安全性。

问题:如果用户输入具有 ImageResizer.dll 识别属性的图像的直接路径,我的自定义处理程序将被忽略并显示图像。

预期目标:

1) 无论提供的任何查询字符串参数如何,当路径匹配时都会触发我的客户图像处理程序。 (如果我删除 ImageResizer.dll 的 web.config 条目,这将有效)

2) 仅当图像来自以下文件夹或子文件夹时,让 imageresizer.dll 识别 QueryString 参数并进行处理:{SITEROOT}/images/products/

问题:有没有人使用过这个 imageresizer.dll 产品,你能指导我如何配置它以达到我想要的目标吗?

我已经修改了以下配置文件,以显示相关条目我正在使用什么。

{我的安全目录}

我网站上实际路径的占位符值

WebProjectAssembly.HTTPHandlers.MyCustomSecurityHandler

我的自定义 HTTPHandler 类

我的 Web.Config 文件:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />
  </configSections>

  <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 -->
     <pipeline fakeExtensions=".ashx" defaultCommands="autorotate.default=true"/>

     <plugins>
       <add name="DiskCache" />
       <!-- <add name="PrettyGifs" /> -->
       <!-- <add name="SimpleFilters" /> -->
       <!-- <add name="S3Reader" /> -->
     </plugins>  
   </resizer>
  
  <system.web>
    <httpModules>
       <!--This is for IIS7/8 Classic Mode and Cassini-->
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </httpModules>
    <httpHandlers>
      <add verb="*" path="/{MY SECURE DIRECTORY}/*.jpg" type="WebProjectAssembly.HTTPHandlers.MyCustomSecurityHandler" />
    </httpHandlers>
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add verb="*" path="/{MY SECURE DIRECTORY}/*.jpg" name="MyCustomHandler" type="WebProjectAssembly.HTTPHandlers.MyCustomSecurityHandler" />
    </handlers>
    <modules>
      <!--This is for IIS7/8 Integrated mode--> 
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </modules>
  </system.webServer>
</configuration>

【问题讨论】:

    标签: c# c#-4.0 httphandler imageresizer


    【解决方案1】:

    IIS/ASP.NET 不允许您基于目录启用或禁用模块,除非它们是单独的应用程序。

    但是,鉴于您的任务(控制图像访问),您可以将 ImageResizer v4 的 AuthorizeImage 事件与 authorizeAllImages="true" 一起使用。这将触发所有请求,让您实现目标。

    【讨论】:

    • 嘿 Nathanael,使用类似的东西的唯一问题是我不希望所有经过身份验证的用户都可以访问所有安全图像。我只希望用户 A 能够看到用户 A 上传的图像。用户 B 不应该仅仅因为他们是经过身份验证的用户就可以看到它们。只要用户不厚颜无耻并在 url 路径中使用查询字符串变量,我编写的 HTTPHandler 就会正确地执行该安全性。我知道我可能在安全方面做得过火了,但我不希望人们有任何机会看到他们不应该看到的东西。不过感谢您的建议。
    • 您可以通过使用 Config.Current.Pipeline.AuthorizeImage 来实现这种安全性——无论是否有查询字符串。您可以访问用户的身份和 HttpContext。与您可以通过处理程序访问的数据相同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多