[英]Why do I get a 500 when I add a rewrite rule to my Web.config in Azure?
[英]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.