Skip to content

Instantly share code, notes, and snippets.

<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>
@scottsauber
scottsauber / project.json
Last active March 10, 2017 15:16
Old Razor Pre-compilation project.json
{
"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"
<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>
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// other code removed for brevity
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// when an exception occurs, route to /Home/Error
app.UseExceptionHandler("/Home/Error");
using System;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace GlobalExceptionHandling.Controllers
{
public class HomeController : Controller
{
public IActionResult Error()
{
@scottsauber
scottsauber / Startup.cs
Created May 22, 2017 02:28
Health Check Startup.cs
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();
}
[Route("api/[controller]")]
public class HealthCheckController : Controller
{
private readonly IHealthCheckService _healthCheckService;
public HealthCheckController(IHealthCheckService healthCheckService)
{
_healthCheckService = healthCheckService;
}
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));
});
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();
}