为特定 URL 提供 app_offline.htm 时,将 http 状态 503 更改为 200
ASP.NET 提供的 app_offline.htm 文件返回 http 状态 503。对于大多数情况,这是正确的行为。但是,在请求特定 URL 的情况下(例如 https://www.mywebsite.com/monitor),我'我希望将返回的 http 状态更改为 200,同时在所有其他情况下仍返回 http 状态 503。这可能吗?
我想要这样做的原因是,每当我们在网站上进行定期维护时,我们都会使用 app_offline.htm 文件,但我们不希望正常运行时间监控服务 (Pingdom.com) 在定期维护期间报告停机时间。
我认为这必须在 IIS 级别,因为 app_offline.htm 在请求处理周期的早期就得到服务。
The app_offline.htm file that ASP.NET serves returns the http status 503. This is the correct behavior for most situations. However, in the scenario where a specific URL is requested (e.g. https://www.mywebsite.com/monitor), I'd like to change the returned http status to 200, while still returning http status 503 in all other situations. Is this possible?
The reason why I want to do this is whenever we do scheduled maintenance on our website, we use the app_offline.htm file, but we don't want our uptime monitoring service (Pingdom.com) to report downtime during our scheduled maintenance.
I assume this would have to be at the IIS level because the app_offline.htm gets served very early on in the request processing cycle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
请注意,
App_Offline
仅用于删除 ASP.NET 部分,与 IIS 站点无关。所有非 ASP.NET 请求(例如 .htm)都将通过正常的 IIS 管道。也就是说,
HTTP 503
是不可用的服务错误。App_Offline.htm
使站点部分脱机,当站点脱机时,所有 ASP.NET 请求都会收到503
响应,这是正常且正确的。使用 HttpModule 或 ASP.NET 管道中的任何代码绕过此问题不是有效的解决方案。
由于您在维护期间已在 IIS 根目录中创建/复制
App_Offline.htm
,因此我建议添加maintenance.htm
作为的默认文档>/monitor
文件夹或您的 IIS 站点,并在维护期间在其中创建/复制maintenance.htm
文件:然后无论 ASP.NET 站点是否离线,都将访问默认页面。如果您的探测器在没有指定任何页面的情况下调用
http://servername/monitor/
uri,它将起作用。您只需在维护后删除它 - 就像删除您的
App_Offline
一样。Note that
App_Offline
is only there to take the ASP.NET part down, it has nothing to do with the IIS site. All non-ASP.NET request -like .htm- will go through the normal IIS pipeline.That being said, a
HTTP 503
is an unavailable service error. TheApp_Offline.htm
take the site partially offline, it is normal and correct that all ASP.NET request get a503
response when the site is offline.Bypass this with a HttpModule or whatever code in the ASP.NET pipeline is not a valid solution.
Since you'are already creating/copying the
App_Offline.htm
in your IIS root during maintenance, I'll suggest to addmaintenance.htm
as a default document for your/monitor
folder or your IIS site and create/copy amaintenance.htm
file in it during maintenance : then the default page will be reach whatever the ASP.NET site is offline or not.If your probe is calling the
http://servername/monitor/
uri without any page specified, it will work.You just have to delete it -like you delete your
App_Offline
- after the maintenance.据我所知,app_offline.htm 逻辑是在 ASP.NET 2.0 模块内部处理的,但在任何应用程序加载开始之前(这当然是 app_offline.htm *g* 背后的想法)。
我建议:
monitor
的虚拟目录添加到您(已禁用)网站的根目录,并将其分配给某个 IIS 可读的文件夹。default.htm
(或默认文件名列表中的任何内容)的app_offline.htm
文件的副本放入该文件夹中。这样,当访问
https://www.mywebsite.com/monitor
时,IIS 应该为 html 文件提供 200 响应。啊,为了遵守 Adilson 关于搜索引擎的警告,只需将
添加到您的文件中,以防搜索引擎可以访问该网站。
As far as I know, the app_offline.htm logic is handled inside the ASP.NET 2.0 module but before any application loading begins (which is of course the idea behind app_offline.htm *g*).
I suggest:
monitor
to the root of your (disabled) Website and assign it to some IIS-readable folder.app_offline.htm
file renamed todefault.htm
(or whatever is in your default filename list) into that folder.This way IIS should serve the html file with a 200 response when accessing
https://www.mywebsite.com/monitor
.Ah, and to honor Adilson's warning about search engines, just add a
<meta name="robots" content="noindex">
to your file in case the website is reachable by search engines.如果您使用的是 IIS 7 和集成管道,您仍然可以为不属于 ASP.NET 管道的请求(i/e .Htm 请求)创建 HttpModule。
http:// learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/
ASP.NET IIS 7 生命周期
http://learn.iis.net/page.aspx/121/iis-7-modules-overview/
If you're using IIS 7 and the integrated pipeline you can still create a HttpModule for requests that are not part of the ASP.NET pipeline, i/e .Htm requests.
http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/
ASP.NET IIS 7 lifecycle
http://learn.iis.net/page.aspx/121/iis-7-modules-overview/
您可以处理 Global.asax Application_Error 方法,识别您的 url,识别您的错误,重定向到您的页面
这将为您之前的请求返回第一个 302,然后重定向到显示 200 的页面...
You could handle the Global.asax Application_Error method, identify your url, identify your error, redirect to your page
This will return first 302 for your previous request, and then redirects to a page that shows 200...
您可以在 IIS 级别使用 http 重定向。
You could use http redirect at the IIS level.
嘿伙计。这样做时要小心! 200 响应可以使您的错误页面被谷歌和其他搜索引擎索引。
如果您仍然选择这样做,我认为您应该创建一个 HttpModule,并将其放在模块堆栈的顶部。该模块必须测试 App_offline.html 文件是否存在,如果存在,则测试请求是否来自站点监视器。在这种情况下,您可以使用 200 进行响应,否则,响应代码必须是 503 以避免错误的站点索引。
重要提示:您的站点应用程序池必须处于集成模式。
Hey man. Take care when doing this! A 200 response can do your error page be indexed by google and others search engines.
If you still choose to do so, I think you should create a HttpModule, and put it on the top of the module stack. This module must test if the App_offline.html file exists, if so, then you test if the request came from the Site Monitor. In this case you can response with a 200, otherwise, the response code must be 503 to avoid bad site indexing.
Important: your site application pool must be in Integrated Mode.