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?
ASP.NET服务的app_offline.htm文件返回http状态503.这是大多数情况下的正确行为。但是,在请求特定URL的情况下(例如https://www.mywebsite.com/monitor),我想将返回的http状态更改为200,同时在所有其他情况下仍返回http状态503。这可能吗?
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.
我想这样做的原因是,无论何时我们在我们的网站上进行定期维护,我们都使用app_offline.htm文件,但我们不希望我们的正常运行时间监控服务(Pingdom.com)在我们的计划维护期间报告停机时间。
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.
我认为这必须在IIS级别,因为app_offline.htm在请求处理周期中很早就得到了服务。
6 个解决方案
#1
9
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.
请注意,App_Offline仅用于将ASP.NET部分关闭,它与IIS站点无关。所有nonASP.NET请求类似.htm-将通过正常的IIS管道。
That being said, a HTTP 503
is an unavailable service error. The App_Offline.htm
take the site partially offline, it is normal and correct that all ASP.NET request get a 503
response when the site is offline.
话虽这么说,HTTP 503是不可用的服务错误。 App_Offline.htm使站点部分脱机,当站点脱机时,所有ASP.NET请求都得到503响应是正常和正确的。
Bypass this with a HttpModule or whatever code in the ASP.NET pipeline is not a valid solution.
使用HttpModule绕过它,或者ASP.NET管道中的任何代码都不是有效的解决方案。
Since you'are already creating/copying the App_Offline.htm
in your IIS root during maintenance, I'll suggest to add maintenance.htm
as a default document for your /monitor
folder or your IIS site and create/copy a maintenance.htm
file in it during maintenance : then the default page will be reach whatever the ASP.NET site is offline or not.
由于您在维护期间已经在IIS根目录中创建/复制App_Offline.htm,因此我建议将maintenance.htm添加为/ monitor文件夹或IIS站点的默认文档,并创建/复制maintenance.htm文件在维护期间使用它:然后无论ASP.NET站点是否脱机,都将访问默认页面。
If your probe is calling the http://servername/monitor/
uri without any page specified, it will work.
如果您的探针在没有指定任何页面的情况下调用http:// servername / monitor / uri,它将起作用。
You just have to delete it -like you delete your App_Offline
- after the maintenance.
您只需删除它 - 就像您在维护后删除App_Offline一样。
#2
2
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*).
据我所知,app_offline.htm逻辑在ASP.NET 2.0模块中处理,但在任何应用程序加载开始之前(这当然是app_offline.htm * g *背后的想法)。
I suggest:
我建议:
- Add a virtual directory named
monitor
to the root of your (disabled) Website and assign it to some IIS-readable folder. - 将名为monitor的虚拟目录添加到(禁用)网站的根目录,并将其分配给某个IIS可读文件夹。
- Do not make the virtual directory an application, so ASP.NET should keep its hands off that folder.
- 不要将虚拟目录设置为应用程序,因此ASP.NET应该保留该文件夹。
- Put e.g. a copy of your
app_offline.htm
file renamed todefault.htm
(or whatever is in your default filename list) into that folder. - 举例来说将app_offline.htm文件的副本重命名为default.htm(或默认文件名列表中的任何内容)到该文件夹中。
This way IIS should serve the html file with a 200 response when accessing https://www.mywebsite.com/monitor
.
这样,IIS在访问https://www.mywebsite.com/monitor时应该以200响应提供html文件。
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.
啊,为了纪念Adilson关于搜索引擎的警告,只需在您的文件中添加 ,以防搜索引擎访问该网站。
#3
2
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.
如果您正在使用IIS 7和集成管道,您仍然可以为不属于ASP.NET管道的请求创建HttpModule,即i / e .Htm请求。
http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/
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/
http://learn.iis.net/page.aspx/121/iis-7-modules-overview/
#5
0
You could handle the Global.asax Application_Error method, identify your url, identify your error, redirect to your page
您可以处理Global.asax Application_Error方法,识别您的网址,识别您的错误,重定向到您的网页
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ctx = HttpContext.Current
dim myerror = ctx.Error
If HttpContext.Current.Request.Path = "mypath" Then
HttpContext.Current.Response.Redirect("~/mydestpage.aspx")
End If
End Sub
This will return first 302 for your previous request, and then redirects to a page that shows 200...
这将首先返回先前请求的302,然后重定向到显示200的页面...
#6
0
Hey man. Take care when doing this! A 200 response can do your error page be indexed by google and others search engines.
嗨,老兄。这样做时要小心! 200响应可以让您的错误页面被谷歌和其他搜索引擎索引。
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.
如果您仍然选择这样做,我认为您应该创建一个HttpModule,并将其放在模块堆栈的顶部。此模块必须测试App_offline.html文件是否存在,如果存在,则测试该请求是否来自站点监视器。在这种情况下,您可以使用200响应,否则,响应代码必须为503以避免错误的站点索引。
Important: your site application pool must be in Integrated Mode.
重要提示:您的站点应用程序池必须处于集成模式。
#1
9
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.
请注意,App_Offline仅用于将ASP.NET部分关闭,它与IIS站点无关。所有nonASP.NET请求类似.htm-将通过正常的IIS管道。
That being said, a HTTP 503
is an unavailable service error. The App_Offline.htm
take the site partially offline, it is normal and correct that all ASP.NET request get a 503
response when the site is offline.
话虽这么说,HTTP 503是不可用的服务错误。 App_Offline.htm使站点部分脱机,当站点脱机时,所有ASP.NET请求都得到503响应是正常和正确的。
Bypass this with a HttpModule or whatever code in the ASP.NET pipeline is not a valid solution.
使用HttpModule绕过它,或者ASP.NET管道中的任何代码都不是有效的解决方案。
Since you'are already creating/copying the App_Offline.htm
in your IIS root during maintenance, I'll suggest to add maintenance.htm
as a default document for your /monitor
folder or your IIS site and create/copy a maintenance.htm
file in it during maintenance : then the default page will be reach whatever the ASP.NET site is offline or not.
由于您在维护期间已经在IIS根目录中创建/复制App_Offline.htm,因此我建议将maintenance.htm添加为/ monitor文件夹或IIS站点的默认文档,并创建/复制maintenance.htm文件在维护期间使用它:然后无论ASP.NET站点是否脱机,都将访问默认页面。
If your probe is calling the http://servername/monitor/
uri without any page specified, it will work.
如果您的探针在没有指定任何页面的情况下调用http:// servername / monitor / uri,它将起作用。
You just have to delete it -like you delete your App_Offline
- after the maintenance.
您只需删除它 - 就像您在维护后删除App_Offline一样。
#2
2
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*).
据我所知,app_offline.htm逻辑在ASP.NET 2.0模块中处理,但在任何应用程序加载开始之前(这当然是app_offline.htm * g *背后的想法)。
I suggest:
我建议:
- Add a virtual directory named
monitor
to the root of your (disabled) Website and assign it to some IIS-readable folder. - 将名为monitor的虚拟目录添加到(禁用)网站的根目录,并将其分配给某个IIS可读文件夹。
- Do not make the virtual directory an application, so ASP.NET should keep its hands off that folder.
- 不要将虚拟目录设置为应用程序,因此ASP.NET应该保留该文件夹。
- Put e.g. a copy of your
app_offline.htm
file renamed todefault.htm
(or whatever is in your default filename list) into that folder. - 举例来说将app_offline.htm文件的副本重命名为default.htm(或默认文件名列表中的任何内容)到该文件夹中。
This way IIS should serve the html file with a 200 response when accessing https://www.mywebsite.com/monitor
.
这样,IIS在访问https://www.mywebsite.com/monitor时应该以200响应提供html文件。
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.
啊,为了纪念Adilson关于搜索引擎的警告,只需在您的文件中添加 ,以防搜索引擎访问该网站。
#3
2
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.
如果您正在使用IIS 7和集成管道,您仍然可以为不属于ASP.NET管道的请求创建HttpModule,即i / e .Htm请求。
http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/
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/
http://learn.iis.net/page.aspx/121/iis-7-modules-overview/
#4
#5
0
You could handle the Global.asax Application_Error method, identify your url, identify your error, redirect to your page
您可以处理Global.asax Application_Error方法,识别您的网址,识别您的错误,重定向到您的网页
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ctx = HttpContext.Current
dim myerror = ctx.Error
If HttpContext.Current.Request.Path = "mypath" Then
HttpContext.Current.Response.Redirect("~/mydestpage.aspx")
End If
End Sub
This will return first 302 for your previous request, and then redirects to a page that shows 200...
这将首先返回先前请求的302,然后重定向到显示200的页面...
#6
0
Hey man. Take care when doing this! A 200 response can do your error page be indexed by google and others search engines.
嗨,老兄。这样做时要小心! 200响应可以让您的错误页面被谷歌和其他搜索引擎索引。
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.
如果您仍然选择这样做,我认为您应该创建一个HttpModule,并将其放在模块堆栈的顶部。此模块必须测试App_offline.html文件是否存在,如果存在,则测试该请求是否来自站点监视器。在这种情况下,您可以使用200响应,否则,响应代码必须为503以避免错误的站点索引。
Important: your site application pool must be in Integrated Mode.
重要提示:您的站点应用程序池必须处于集成模式。