强制Sitecore处理对文件的任何请求(。*)

时间:2014-11-26 15:22:30

标签: url iis request rewrite sitecore

如何强制Sitecore处理任何文件请求,而不是从IIS获取404。 原因是,我们希望能够将URL重写模块(http://github.com/ParTech/Url-Rewriter)应用于文件请求。

实施例: 用户请求:http://sitecore.domain/randomfolder/file.pdf(存在剂量)

但是我们希望Sitecore接收请求并应用任何重写规则(如果可用),而不是获取IIS“HTTP错误404.0 - 通过StaticFile找不到”,而是使用Sitecore notfound页面。

我尝试过将不同的处理程序添加到system.webserver但没有成功,以及在IIS设置上直接修改Handler Mappings。

1 个答案:

答案 0 :(得分:8)

我不确定您是否应该去那里,因为所有请求都将通过Sitecore,但如果您需要,可以更改此配置:

<preprocessRequest>
  <processor type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
    <param desc="Allowed extensions (comma separated)">aspx</param>
    <param desc="Blocked extensions (comma separated)">*</param>
    <param desc="Blocked extensions that stream files (comma separated)">css,js</param>
    <param desc="Blocked extensions that do not stream files (comma separated)">*</param>
  </processor>
</preprocessRequest>

将允许的扩展名设置为*并将阻止的扩展名设置为空(未测试) 如果你知道要重定向的扩展名(例如只是PDF文件),那么只能在允许的扩展名设置中定义(我建议你这样做)。

<param desc="Allowed extensions (comma separated)">aspx,pdf</param>

我认为这是URL重写器模块处理请求所需的唯一内容 请记住,该模块要处理的文件请求未经测试且不受支持,但理论上它应该可以正常工作。