Make all templates as consistent as possible with stock MVC Core 2.0 one

This commit is contained in:
Steve Sanderson
2017-05-19 11:36:17 +01:00
parent 3ee16a5ba5
commit 42b88c15f2
64 changed files with 521 additions and 375 deletions

View File

@@ -1,23 +1,25 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable> <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
</ItemGroup>
<ItemGroup>
<!-- Files not to show in IDE -->
<None Remove="yarn.lock" />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
</ItemGroup>
<ItemGroup>
<!-- Files not to publish (note that the 'dist' subfolders are re-added below) --> <!-- Files not to publish (note that the 'dist' subfolders are re-added below) -->
<Content Remove="ClientApp\**" /> <Content Remove="ClientApp\**" />
</ItemGroup> </ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish"> <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" /> <Exec Command="npm install" />
@@ -33,4 +35,5 @@
</ResolvedFileToPublish> </ResolvedFileToPublish>
</ItemGroup> </ItemGroup>
</Target> </Target>
</Project> </Project>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -15,6 +16,7 @@ namespace WebApplicationBasic.Controllers
public IActionResult Error() public IActionResult Error()
{ {
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View(); return View();
} }
} }

View File

@@ -3,7 +3,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
@@ -11,14 +14,12 @@ namespace WebApplicationBasic
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() BuildWebHost(args).Run();
.UseKestrel() }
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
host.Run();
}
} }
} }

View File

@@ -7,41 +7,32 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services.
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true HotModuleReplacement = true
}); });
} }

View File

@@ -4,3 +4,18 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (!string.IsNullOrEmpty((string)ViewData["RequestId"]))
{
<p>
<strong>Request ID:</strong> <code>@ViewData["RequestId"]</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>

View File

@@ -4,7 +4,8 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebApplicationBasic</title> <title>@ViewData["Title"] - WebApplicationBasic</title>
<base href="/" /> <base href="~/" />
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
</head> </head>
<body> <body>

View File

@@ -1,3 +1,3 @@
@using WebApplicationBasic @using WebApplicationBasic
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "*, Microsoft.AspNetCore.SpaServices" @addTagHelper *, Microsoft.AspNetCore.SpaServices

View File

@@ -0,0 +1,19 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}

View File

@@ -1,10 +1,15 @@
{ {
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"Debug": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Warning"
"System": "Information", }
"Microsoft": "Information" },
"Console": {
"LogLevel": {
"Default": "Warning"
}
} }
} }
} }

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

View File

@@ -1,20 +1,20 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable> <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-*" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- Files not to show in IDE --> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
<None Remove="yarn.lock" />
</ItemGroup> </ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish"> <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" /> <Exec Command="npm install" />
@@ -30,4 +30,5 @@
</ResolvedFileToPublish> </ResolvedFileToPublish>
</ItemGroup> </ItemGroup>
</Target> </Target>
</Project> </Project>

View File

@@ -9,7 +9,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="#/home">Aurelia</a> <a class="navbar-brand" href="#/home">WebApplicationBasic</a>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="navbar-collapse collapse"> <div class="navbar-collapse collapse">

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -15,6 +16,7 @@ namespace WebApplicationBasic.Controllers
public IActionResult Error() public IActionResult Error()
{ {
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View(); return View();
} }
} }

View File

@@ -3,7 +3,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
@@ -11,14 +14,12 @@ namespace WebApplicationBasic
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() BuildWebHost(args).Run();
.UseKestrel() }
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
host.Run();
}
} }
} }

View File

@@ -7,42 +7,32 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services.
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { {
HotModuleReplacement = true HotModuleReplacement = true
}); });
} }

View File

@@ -4,3 +4,18 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (!string.IsNullOrEmpty((string)ViewData["RequestId"]))
{
<p>
<strong>Request ID:</strong> <code>@ViewData["RequestId"]</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>

View File

@@ -3,7 +3,8 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Aurelia</title> <title>@ViewData["Title"] - WebApplicationBasic</title>
<base href="~/" />
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
</head> </head>

View File

@@ -1,3 +1,3 @@
@using WebApplicationBasic @using WebApplicationBasic
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "*, Microsoft.AspNetCore.SpaServices" @addTagHelper *, Microsoft.AspNetCore.SpaServices

View File

@@ -0,0 +1,19 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}

View File

@@ -1,10 +1,15 @@
{ {
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"Debug": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Warning"
"System": "Information", }
"Microsoft": "Information" },
"Console": {
"LogLevel": {
"Default": "Warning"
}
} }
} }
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -15,6 +16,7 @@ namespace WebApplicationBasic.Controllers
public IActionResult Error() public IActionResult Error()
{ {
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View(); return View();
} }
} }

View File

@@ -1,20 +1,20 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable> <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-*" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- Files not to show in IDE --> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
<None Remove="yarn.lock" />
</ItemGroup> </ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish"> <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" /> <Exec Command="npm install" />
@@ -30,4 +30,5 @@
</ResolvedFileToPublish> </ResolvedFileToPublish>
</ItemGroup> </ItemGroup>
</Target> </Target>
</Project> </Project>

View File

@@ -3,7 +3,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
@@ -11,14 +14,12 @@ namespace WebApplicationBasic
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() BuildWebHost(args).Run();
.UseKestrel() }
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
host.Run();
}
} }
} }

View File

@@ -7,37 +7,27 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services.
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();

View File

@@ -4,3 +4,18 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (!string.IsNullOrEmpty((string)ViewData["RequestId"]))
{
<p>
<strong>Request ID:</strong> <code>@ViewData["RequestId"]</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>

View File

@@ -4,9 +4,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebApplicationBasic</title> <title>@ViewData["Title"] - WebApplicationBasic</title>
<base href="~/" />
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
<environment names="Staging,Production"> <environment exclude="Development">
<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />
</environment> </environment>
</head> </head>

View File

@@ -1,3 +1,3 @@
@using WebApplicationBasic @using WebApplicationBasic
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "*, Microsoft.AspNetCore.SpaServices" @addTagHelper *, Microsoft.AspNetCore.SpaServices

View File

@@ -0,0 +1,19 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}

View File

@@ -1,10 +1,15 @@
{ {
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"Debug": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Warning"
"System": "Information", }
"Microsoft": "Information" },
"Console": {
"LogLevel": {
"Default": "Warning"
}
} }
} }
} }

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -15,6 +16,7 @@ namespace WebApplicationBasic.Controllers
public IActionResult Error() public IActionResult Error()
{ {
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View(); return View();
} }
} }

View File

@@ -3,7 +3,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
@@ -11,14 +14,12 @@ namespace WebApplicationBasic
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() BuildWebHost(args).Run();
.UseKestrel() }
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
host.Run();
}
} }
} }

View File

@@ -1,23 +1,25 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable> <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
</ItemGroup>
<ItemGroup>
<!-- Files not to show in IDE -->
<None Remove="yarn.lock" />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
</ItemGroup>
<ItemGroup>
<!-- Files not to publish (note that the 'dist' subfolders are re-added below) --> <!-- Files not to publish (note that the 'dist' subfolders are re-added below) -->
<Content Remove="ClientApp\**" /> <Content Remove="ClientApp\**" />
</ItemGroup> </ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish"> <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" /> <Exec Command="npm install" />
@@ -33,4 +35,5 @@
</ResolvedFileToPublish> </ResolvedFileToPublish>
</ItemGroup> </ItemGroup>
</Target> </Target>
</Project> </Project>

View File

@@ -7,41 +7,32 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services.
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true, HotModuleReplacement = true,
ReactHotModuleReplacement = true ReactHotModuleReplacement = true
}); });

View File

@@ -4,3 +4,18 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (!string.IsNullOrEmpty((string)ViewData["RequestId"]))
{
<p>
<strong>Request ID:</strong> <code>@ViewData["RequestId"]</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>

View File

@@ -4,6 +4,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebApplicationBasic</title> <title>@ViewData["Title"] - WebApplicationBasic</title>
<base href="~/" />
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />

View File

@@ -1,3 +1,3 @@
@using WebApplicationBasic @using WebApplicationBasic
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "*, Microsoft.AspNetCore.SpaServices" @addTagHelper *, Microsoft.AspNetCore.SpaServices

View File

@@ -0,0 +1,19 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}

View File

@@ -1,10 +1,15 @@
{ {
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"Debug": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Warning"
"System": "Information", }
"Microsoft": "Information" },
"Console": {
"LogLevel": {
"Default": "Warning"
}
} }
} }
} }

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -15,6 +16,7 @@ namespace WebApplicationBasic.Controllers
public IActionResult Error() public IActionResult Error()
{ {
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View(); return View();
} }
} }

View File

@@ -3,7 +3,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
@@ -11,14 +14,12 @@ namespace WebApplicationBasic
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() BuildWebHost(args).Run();
.UseKestrel() }
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
host.Run();
}
} }
} }

View File

@@ -1,20 +1,20 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable> <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-*" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- Files not to show in IDE --> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
<None Remove="yarn.lock" />
</ItemGroup> </ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish"> <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" /> <Exec Command="npm install" />
@@ -30,4 +30,5 @@
</ResolvedFileToPublish> </ResolvedFileToPublish>
</ItemGroup> </ItemGroup>
</Target> </Target>
</Project> </Project>

View File

@@ -7,41 +7,32 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services.
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true, HotModuleReplacement = true,
ReactHotModuleReplacement = true ReactHotModuleReplacement = true
}); });

View File

@@ -4,3 +4,18 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (!string.IsNullOrEmpty((string)ViewData["RequestId"]))
{
<p>
<strong>Request ID:</strong> <code>@ViewData["RequestId"]</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>

View File

@@ -4,9 +4,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebApplicationBasic</title> <title>@ViewData["Title"] - WebApplicationBasic</title>
<base href="~/" />
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
<environment names="Staging,Production"> <environment exclude="Development">
<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />
</environment> </environment>
</head> </head>

View File

@@ -1,3 +1,3 @@
@using WebApplicationBasic @using WebApplicationBasic
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "*, Microsoft.AspNetCore.SpaServices" @addTagHelper *, Microsoft.AspNetCore.SpaServices

View File

@@ -0,0 +1,19 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}

View File

@@ -1,10 +1,15 @@
{ {
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"Debug": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Warning"
"System": "Information", }
"Microsoft": "Information" },
"Console": {
"LogLevel": {
"Default": "Warning"
}
} }
} }
} }

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

View File

@@ -1,3 +1,4 @@
import './css/site.css';
import 'bootstrap'; import 'bootstrap';
import Vue from 'vue'; import Vue from 'vue';
import VueRouter from 'vue-router'; import VueRouter from 'vue-router';

View File

@@ -19,13 +19,6 @@
z-index: 1; z-index: 1;
} }
@media (max-width: 767px) {
/* On small screens, the nav menu spans the full width of the screen. Leave a space for it. */
body {
padding-top: 50px;
}
}
@media (min-width: 768px) { @media (min-width: 768px) {
/* On small screens, convert the nav menu to a vertical sidebar */ /* On small screens, convert the nav menu to a vertical sidebar */
.main-nav { .main-nav {

View File

@@ -0,0 +1,6 @@
@media (max-width: 767px) {
/* On small screens, the nav menu spans the full width of the screen. Leave a space for it. */
body {
padding-top: 50px;
}
}

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -15,6 +16,7 @@ namespace WebApplicationBasic.Controllers
public IActionResult Error() public IActionResult Error()
{ {
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View(); return View();
} }
} }

View File

@@ -3,7 +3,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
@@ -11,14 +14,12 @@ namespace WebApplicationBasic
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() BuildWebHost(args).Run();
.UseKestrel() }
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
host.Run();
}
} }
} }

View File

@@ -7,41 +7,32 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebApplicationBasic namespace WebApplicationBasic
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services.
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true HotModuleReplacement = true
}); });
} }

View File

@@ -4,3 +4,18 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (!string.IsNullOrEmpty((string)ViewData["RequestId"]))
{
<p>
<strong>Request ID:</strong> <code>@ViewData["RequestId"]</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>

View File

@@ -4,8 +4,12 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebApplicationBasic</title> <title>@ViewData["Title"] - WebApplicationBasic</title>
<base href="~/" />
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" /> <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
<environment exclude="Development">
<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />
</environment>
</head> </head>
<body> <body>
@RenderBody() @RenderBody()

View File

@@ -1,3 +1,3 @@
@using WebApplicationBasic @using WebApplicationBasic
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "*, Microsoft.AspNetCore.SpaServices" @addTagHelper *, Microsoft.AspNetCore.SpaServices

View File

@@ -1,20 +1,20 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable> <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-*" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- Files not to show in IDE --> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
<None Remove="yarn.lock" />
</ItemGroup> </ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish"> <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" /> <Exec Command="npm install" />
@@ -30,4 +30,5 @@
</ResolvedFileToPublish> </ResolvedFileToPublish>
</ItemGroup> </ItemGroup>
</Target> </Target>
</Project> </Project>

View File

@@ -0,0 +1,19 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}

View File

@@ -1,10 +1,15 @@
{ {
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"Debug": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Warning"
"System": "Information", }
"Microsoft": "Information" },
"Console": {
"LogLevel": {
"Default": "Warning"
}
} }
} }
} }

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

View File

@@ -45,7 +45,8 @@ module.exports = (env) => {
}) })
] : [ ] : [
// Plugins that apply in production builds only // Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin() new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('site.css')
]) ])
}]; }];
}; };