ImageResizer 无法在重写事件中应用预设(预设已展开)
ImageResizer Can't apply Preset in Rewrite Event (Presets already expanded)
我需要能够分析请求的图像 URL 并根据请求的 URL 应用调整大小命令,而不让用户看到 url 中的调整大小命令。例如
http://someurl.com/image/category/image-title.jpg
为此,我已连接到 Pipeline_Rewrite - 下面的基本示例:
void Pipeline_Rewrite(IHttpModule sender, HttpContext context, ImageResizer.Configuration.IUrlEventArgs e)
{
// Clear the current command string - we're going to create a new one
e.QueryString.Clear();
var process = ((Global)HttpContext.Current.ApplicationInstance).ContainerProvider.RequestLifetime.Resolve<Interfaces.IRequestBuilder>();
// Set the "new" command string
e.QueryString = process.BuildCommandList(context);
}
BuildCommandList(context)
分析当前的 url 并构造一个适当的命令列表以添加到查询字符串,以及 returns 一个 NameValueCollection
。这一切都很好,并且应用了命令,除非新命令是配置中定义的 Preset
。
例如
如果 BuildCommandList(context)
returns 等价于 width=150&height=150
,这有效。
如果 BuildCommandList(context)
returns 等同于 preset=thumbnail
这不起作用,我只得到完整尺寸的原始图像。
经进一步调查,似乎在 Pipeline_Rewrite
方法运行之前,任何预设命令都已扩展到其相关命令字符串,因此在此处添加它们为时已晚。
从 web.config 文件中提取:
<resizer>
<presets onlyAllowPresets="false">
<preset name="thumbnail" settings="width=150;height=150" />
</presets>
<plugins>
<add name="Presets" />
</plugins>
</resizer>
此时有什么方法可以清除命令字符串,应用预设,并让ImageResizer 重新处理预设吗?
如果您希望 Presets 与您的事件处理程序一起使用,您的事件处理程序需要先注册。
我建议从 web.config 中删除 <add name="Presets" />
,而是在注册事件处理程序后通过 new ImageResizer.Plugins.Basic.Presets().Install(Config.Current);
安装它
我需要能够分析请求的图像 URL 并根据请求的 URL 应用调整大小命令,而不让用户看到 url 中的调整大小命令。例如
http://someurl.com/image/category/image-title.jpg
为此,我已连接到 Pipeline_Rewrite - 下面的基本示例:
void Pipeline_Rewrite(IHttpModule sender, HttpContext context, ImageResizer.Configuration.IUrlEventArgs e)
{
// Clear the current command string - we're going to create a new one
e.QueryString.Clear();
var process = ((Global)HttpContext.Current.ApplicationInstance).ContainerProvider.RequestLifetime.Resolve<Interfaces.IRequestBuilder>();
// Set the "new" command string
e.QueryString = process.BuildCommandList(context);
}
BuildCommandList(context)
分析当前的 url 并构造一个适当的命令列表以添加到查询字符串,以及 returns 一个 NameValueCollection
。这一切都很好,并且应用了命令,除非新命令是配置中定义的 Preset
。
例如
如果 BuildCommandList(context)
returns 等价于 width=150&height=150
,这有效。
如果 BuildCommandList(context)
returns 等同于 preset=thumbnail
这不起作用,我只得到完整尺寸的原始图像。
经进一步调查,似乎在 Pipeline_Rewrite
方法运行之前,任何预设命令都已扩展到其相关命令字符串,因此在此处添加它们为时已晚。
从 web.config 文件中提取:
<resizer>
<presets onlyAllowPresets="false">
<preset name="thumbnail" settings="width=150;height=150" />
</presets>
<plugins>
<add name="Presets" />
</plugins>
</resizer>
此时有什么方法可以清除命令字符串,应用预设,并让ImageResizer 重新处理预设吗?
如果您希望 Presets 与您的事件处理程序一起使用,您的事件处理程序需要先注册。
我建议从 web.config 中删除 <add name="Presets" />
,而是在注册事件处理程序后通过 new ImageResizer.Plugins.Basic.Presets().Install(Config.Current);