为特定 URL 提供 app_offline.htm 时,将 http 状态 503 更改为 200

发布于 2024-10-19 02:07:44 字数 394 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

记忆之渊 2024-10-26 02:07:44

请注意,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. 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.

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

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.

傲性难收 2024-10-26 02:07:44

据我所知,app_offline.htm 逻辑是在 ASP.NET 2.0 模块内部处理的,但在任何应用程序加载开始之前(这当然是 app_offline.htm *g* 背后的想法)。

我建议:

  • 将名为 monitor 的虚拟目录添加到您(已禁用)网站的根目录,并将其分配给某个 IIS 可读的文件夹。
  • 不要将虚拟目录作为应用程序,因此 ASP.NET 应该远离该文件夹。
  • 将例如重命名为 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:

  • Add a virtual directory named monitor to the root of your (disabled) Website and assign it to some IIS-readable folder.
  • Do not make the virtual directory an application, so ASP.NET should keep its hands off that folder.
  • Put e.g. a copy of your app_offline.htm file renamed to default.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.

请你别敷衍 2024-10-26 02:07:44

如果您使用的是 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/

空城旧梦 2024-10-26 02:07:44

您可以处理 Global.asax Application_Error 方法,识别您的 url,识别您的错误,重定向到您的页面

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

这将为您之前的请求返回第一个 302,然后重定向到显示 200 的页面...

You could handle the Global.asax Application_Error method, identify your url, identify your error, redirect to your page

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

风苍溪 2024-10-26 02:07:44

您可以在 IIS 级别使用 http 重定向

You could use http redirect at the IIS level.

雾里花 2024-10-26 02:07:44

嘿伙计。这样做时要小心! 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文