繁体   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