View renderer.cs
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using ClassLibrary;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
View attribute.cs
using JetBrains.Annotations;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
[assembly: AspMvcViewLocationFormat(@"~/../ClassLibrary")]
namespace Web
{
public class Startup
View web.xml
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
View controller.cs
using Microsoft.AspNetCore.Mvc;
namespace Web
{
public class DemoController : Controller
{
[Route("/")]
public IActionResult Index()
{
return View("~/MyView.cshtml");
View classlib.xml
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
</ItemGroup>
View extension.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHealthCheck("/hc");
app.Run(async (context) =>
View middleware.cs
public class HealthCheckMiddleware
{
private readonly RequestDelegate _next;
private readonly string _path;
public HealthCheckMiddleware(RequestDelegate next, string path)
{
_next = next;
_path = path;
}
View checkdb.cs
app.Use(async (context, func) =>
{
if (context.Request.Path.Value == "/hc")
{
try
{
using (var db = new SqlConnection("Database=Oops"))
{
await db.OpenAsync();
db.Close();
View startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.Use(async (context, func) =>
{
if (context.Request.Path.Value == "/hc")
View exceptiondetails.cs
public override void Configure(IApplicationBuilder app)
{
app.UseProblemDetails(x =>
{
// This is the default behavior; only include exception details in a development environment.
x.IncludeExceptionDetails = ctx => Environment.IsDevelopment();
});
app.UseMvc();