简体   繁体   English

如何将重写规则添加到 Azure web.config 以便某些请求不会被重定向?

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

How to add a URL Rewrite rule so that requests from user agents – ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0 are not redirected?如何添加 URL 重写规则,以便来自用户代理的请求 – ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0不会被重定向? I need this so Azure app service health check can work.我需要这个,所以 Azure 应用服务健康检查可以工作。

I found many SO posts about redirecting urls but I can't found SO posts for preventing redirection for certain requests.我发现了许多关于重定向 url 的 SO 帖子,但我找不到用于防止某些请求重定向的 SO 帖子。

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.您可以在项目中添加web.config It work for me.它对我有用。

在此处输入图像描述

Method 2方法二

In Startup.cs .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 .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.

相关问题 为什么在向Azure中的Web.config添加重写规则时会获得500? - Why do I get a 500 when I add a rewrite rule to my Web.config in Azure? URL重写模块,Azure和web.config - URL Rewrite Module, Azure and web.config web.config 重写规则在 Blob 存储中的 Azure 静态网站中不起作用 - web.config rewrite rule not working in Azure static website in blob storage 更新 web.config,为 Azure 应用服务的 Azure DevOps 发布管道中的特定环境添加重写规则 - Update web.config to add rewrite rules for specific environments in Azure DevOps release pipeline for an Azure App Service 如何在web.config中重写和/或重定向URL - How to rewrite and/or redirect a url in web.config Azure网站 - 使用web.config重写URL无法正常工作 - Azure web site - URL Rewrite using web.config not working 重写URL的Web.config规则始终从https重定向到http - Web.config rule for rewriting url is always redirected from https to http 如何在 Azure web 应用程序 web.config 文件中添加/设置新的环境变量 - How to add/set new environmental varaible in Azure web app web.config file 在IIS web.config中重写规则“ URL作为参数”(返回错误500) - Rewrite rule “URL as parameter” in IIS web.config (returns error 500) Windows Azure中的web.config - web.config in Windows Azure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM