簡體   English   中英

如何將重寫規則添加到 Azure web.config 以便某些請求不會被重定向?

[英]How to add rewrite rule to Azure web.config so that certain requests are not redirected?

如何添加 URL 重寫規則,以便來自用戶代理的請求 – ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0不會被重定向? 我需要這個,所以 Azure 應用服務健康檢查可以工作。

我發現了許多關於重定向 url 的 SO 帖子,但我找不到用於防止某些請求重定向的 SO 帖子。

這篇文章是對我之前帖子的補充,但我只想關注真正的問題,因為我之前的帖子似乎關注了錯誤的話題。

謝謝你的幫助

您可以在項目中添加web.config 它對我有用。

在此處輸入圖像描述

方法二

Startup.cs中。

public void Configure(IApplicationBuilder app)
{
    app.UseRouting();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapHealthChecks("/health");

        endpoints.MapGet("/{**path}", async context =>
        {
            await context.Response.WriteAsync(
                "Navigate to /health to see the health status.");
        });
    });
}

web.config中。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <urlCompression doDynamicCompression="true" doStaticCompression="true"/>
    <httpCompression>
      <staticTypes>
        <add mimeType="image/svg+xml" enabled="true"/>
      </staticTypes>
    </httpCompression>
    <rewrite>
        <rules>
            <rule name="Root Hit Redirect" stopProcessing="true">
                <match url="^$" />
                <action type="Redirect" url="/health" />
            </rule>
        </rules>
    </rewrite>
  </system.webServer>
</configuration>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM