问题
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
回答1:
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>
来源:https://stackoverflow.com/questions/65639409/how-to-add-rewrite-rule-to-azure-web-config-so-that-certain-requests-are-not-red