Forcing Sitecore to handle any requests to a file (.*)

只愿长相守 提交于 2019-12-08 07:14:38

问题


How could one go about forcing Sitecore to handle any file requests, instead of getting a 404 from the IIS. The reason being, that we want to be able to apply the URL Rewrite Module (http://github.com/ParTech/Url-Rewriter) to file requests aswell.

Example: User requests : http://sitecore.domain/randomfolder/file.pdf (which dosent exists)

But instead of getting the IIS "HTTP Error 404.0 - Not Found via StaticFile", we want Sitecore to pick up the request, and apply any rewrite rules if available, else use the Sitecore notfound page.

I've tried adding different handlers to system.webserver without success, aswell as directly modifying Handler Mappings on the IIS settings.


回答1:


I'm not sure if you should go there, because then all requests will go through Sitecore, but if you want it you can change this configuration:

<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>

Set allowed extensions to * and set blocked extensions to empty (not tested).
If you know which extensions you are going to redirect (e.g. just PDF files), then only define those in the allowed extensions setting (I would suggest you do this).

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

I think that is the only thing needed for the request to be handled by the URL Rewriter module.
Keep in mind that it's untested and unsupported for file requests to be handled by that module, but in theory it should work.



来源:https://stackoverflow.com/questions/27152784/forcing-sitecore-to-handle-any-requests-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!