IIS中特定资源的自定义http状态代码 [英] Custom http status code for specific resource in IIS
问题描述
我的网站上有一个'app_offline.htm'文件。如何配置IIS以使用特定的状态代码(例如209)返回它而不是默认的(200)?
I have a web site with a single 'app_offline.htm' file. How can i configure IIS to return it with specific status code (say, 209) instead of default one (200)?
推荐答案
使用ASP.Net的'app_offline.htm'功能的另一种方法是使用 IIS URL重写模块,它有一个大量的技巧和设置自定义响应代码就是其中之一。
An alternative to using the 'app_offline.htm' feature of ASP.Net could be to use the IIS URL Rewrite Module, it has a huge bag of tricks and setting custom response codes is one of them.
如果页面内容不重要,只有响应代码,那么使用该模块,您可以配置一个规则,该规则将返回带有209代码的空白响应只要规则已启用,任何请求。
If the content of the page is not important, only the response code, then with that module you can configure a rule that will return a blank response with a 209 code to any request as long as the rule is enabled.
这将在你的web.config中实现如下:
That will materialise in your web.config as something like this:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="app_offline" stopProcessing="true">
<match url=".*" />
<action type="CustomResponse" statusCode="209" statusReason="System unavailable" statusDescription="The site is currently down for maintenance, or something." />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这篇关于IIS中特定资源的自定义http状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!