为自定义 httphandler 添加 web.config 静态内容设置
我有一个自定义的 httphandler,它提供来自虚拟文件系统的静态文件。如果我像下面一样配置静态内容部分,我希望这些设置应用于我通过处理程序提供的静态文件。我想我需要将设置添加到我自己的响应中,或者还有其他方法吗?我的处理程序实现了 IHttpHandler 接口。
<location path="Storage">
<system.webServer>
<handlers>
<clear />
<add name="StaticFile" path="*.jpg" verb="*" type="Stormbreaker.Web.StaticFileHandler, Stormbreaker" />
</handlers>
<staticContent>
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
<mimeMap fileExtension=".jpg" mimeType="image/jpeg" />
</staticContent>
</system.webServer>
</location>
I have a custom httphandler that serves static files from a virtual file system. If I configure the static content section like below I would like these settings to apply to the static files i serve via the handler. I guess I need to add the settings to the response my self or is there another way? My handler implements the IHttpHandler interface.
<location path="Storage">
<system.webServer>
<handlers>
<clear />
<add name="StaticFile" path="*.jpg" verb="*" type="Stormbreaker.Web.StaticFileHandler, Stormbreaker" />
</handlers>
<staticContent>
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
<mimeMap fileExtension=".jpg" mimeType="image/jpeg" />
</staticContent>
</system.webServer>
</location>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信 staticContent 仅影响 IIS 附带的 StaticFileHandler。 IIS 无法知道您的处理程序是否提供静态文件,因此您需要在处理程序中自行添加这些标头,但您可能希望使用其自己的部分从 web.config 对其进行配置,以便将来进行更改。
I believe that staticContent only affects the StaticFileHandler which ships with IIS. IIS have no way of knowing that your handler serves static files, so you would need to add those headers your self in your handler, but you might want to make it configurable from your web.config with it's own section for future changes.