Created
May 14, 2020 09:15
-
-
Save alanta/e38948ddd742335237ae85914e4d935d to your computer and use it in GitHub Desktop.
Azure Web Apps with Always On enabled poll your web app every 5 minutes. If there's nothing listening on that url this results in a 404 response which shows up as an error in monitoring.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class AlwaysOn | |
{ | |
/// <summary> | |
/// Prevent 404 on the application root URL. Azure Web Apps with Always On enabled invoke the root of the application every 5 minutes | |
/// to keep your web app awake. If you run an API-only app you likely have nothing listening to /, which results in a 404 response | |
/// that shows up in monitoring. This endpoint returns 200 with content Ok only for the always on check. | |
/// </summary> | |
/// <param name="builder">The application builder.</param> | |
/// <returns>The application builder.</returns> | |
public static IApplicationBuilder UseAlwaysOn(this IApplicationBuilder builder) | |
{ | |
builder.Use(next => async context => | |
{ | |
if (context.Request.Path == "/" && context.Request.Headers.TryGetValue("user-agent", out var value) && value.Equals("AlwaysOn")) | |
{ | |
await context.Response.WriteAsync("Ok"); | |
return; | |
} | |
await next(context); | |
}); | |
return builder; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment