This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checks home page.
- Loading branch information
Showing
2 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.eShopWeb.Web.HealthChecks | ||
{ | ||
public class HomePageHealthCheck : IHealthCheck | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
|
||
public HomePageHealthCheck(IHttpContextAccessor httpContextAccessor) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
} | ||
|
||
public async Task<HealthCheckResult> CheckHealthAsync( | ||
HealthCheckContext context, | ||
CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
string myUrl = _httpContextAccessor.HttpContext.Request.Host.ToString(); | ||
var client = new HttpClient(); | ||
var response = await client.GetAsync(myUrl); | ||
var pageContents = await response.Content.ReadAsStringAsync(); | ||
if (pageContents.Contains(".NET Bot Black Sweatshirt")) | ||
{ | ||
return HealthCheckResult.Healthy("The check indicates a healthy result."); | ||
} | ||
|
||
return HealthCheckResult.Unhealthy("The check indicates an unhealthy result."); | ||
} | ||
} | ||
} |
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