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
<script asp-fallback-test="window.Promise" | |
asp-fallback-src="https://unpkg.com/promise-polyfill@6.0.2"> | |
</script> | |
<script asp-fallback-test="window.fetch" | |
asp-fallback-src="https://unpkg.com/whatwg-fetch@2.0.2"> | |
</script> |
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
{ | |
"dependencies": { | |
"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design": { | |
"version": "1.1.0-preview4-final", | |
"type": "build" | |
} | |
}, | |
"tools": { | |
"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools": "1.1.0-preview4-final" |
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
<Project Sdk="Microsoft.NET.Sdk.Web"> | |
<PropertyGroup> | |
<TargetFramework>netcoreapp1.1</TargetFramework> | |
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish> | |
<PreserveCompilationContext>true</PreserveCompilationContext> | |
</PropertyGroup> | |
<PropertyGroup> | |
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback> |
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 void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | |
{ | |
// other code removed for brevity | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
else | |
{ |
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
// when an exception occurs, route to /Home/Error | |
app.UseExceptionHandler("/Home/Error"); |
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
using System; | |
using Microsoft.AspNetCore.Diagnostics; | |
using Microsoft.AspNetCore.Mvc; | |
namespace GlobalExceptionHandling.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
public IActionResult Error() | |
{ |
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 void ConfigureServices(IServiceCollection services) | |
{ | |
// Creates a HealthCheckBuilder and registers an IHealthCheckService in the IServiceCollection/IoC Container | |
services.AddHealthChecks(checks => | |
{ | |
// Register health checks here | |
}); | |
services.AddMvc(); | |
} |
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
[Route("api/[controller]")] | |
public class HealthCheckController : Controller | |
{ | |
private readonly IHealthCheckService _healthCheckService; | |
public HealthCheckController(IHealthCheckService healthCheckService) | |
{ | |
_healthCheckService = healthCheckService; | |
} |
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 void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHealthChecks(checks => | |
{ | |
// First parameter is the URL you want to check | |
// The second parameter is the CacheDuration of how long you want to hold onto the HealthCheckResult | |
// The default is 5 minutes, and in my case, I don't really want any cache at all | |
// because I don't want to wait up to 5 minutes if my service goes down to be notified about it | |
checks.AddUrlCheck("https://github.com", TimeSpan.FromMilliseconds(1)); | |
}); |
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 void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHealthChecks(checks => | |
{ | |
checks.AddUrlCheck("https://github.com"); | |
checks.AddSqlCheck("Local DB Check", "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplication1;Trusted_Connection=True;MultipleActiveResultSets=true"); | |
}); | |
services.AddMvc(); | |
} |