如何将重写规则添加到Azure web.config,以使某些请求不被重定向? [英] How to add rewrite rule to Azure web.config so that certain requests are not redirected?

查看:48
本文介绍了如何将重写规则添加到Azure web.config,以使某些请求不被重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加URL重写规则,以便来自用户代理的请求– ReadyForRequest/1.0 +(HealthCheck)& HealthCheck/1.0 是否未重定向?我需要这样做,以便Azure应用程序服务运行状况检查可以正常工作.

我发现

方法2

Startup.cs 中.

  public void Configure(IApplicationBuilder应用){app.UseRouting();app.UseEndpoints(endpoints =>{endpoints.MapHealthChecks("/health");endpoints.MapGet("/{** path}",异步上下文=>{等待context.Response.WriteAsync(导航至/health以查看健康状况.");});});} 

web.config 中.

 <?xml version ="1.0"encoding ="utf-8"?<配置>< system.webServer>< urlCompression doDynamicCompression ="true";doStaticCompression ="true"/>< httpCompression>< staticTypes>< add mimeType =" image/svg + xml"enabled ="true"/></staticTypes></httpCompression>< rewrite><规则><规则名称=根目录重定向";stopProcessing ="true"< match url =" ^ $"/>< action type =重定向";url ="/health"/></rule></rules></rewrite></system.webServer></configuration> 

How to add a URL Rewrite rule so that requests from user agents – ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0 are not redirected ? I need this so Azure app service health check can work.

I found many SO posts about redirecting urls but I can't found SO posts for preventing redirection for certain requests.

This post is to add answer to my previous post, but I only want to focus on the real problem because my previous post seems gained attention to the wrong topic.

Thanks for any help

解决方案

You can add web.config in your project. It work for me.

Method 2

In 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.");
        });
    });
}

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

这篇关于如何将重写规则添加到Azure web.config,以使某些请求不被重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆