[英]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.它对我有用。
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.