diff --git a/lib/commands/new/project-template.js b/lib/commands/new/project-template.js index f2f8c23e2..2a709cda6 100644 --- a/lib/commands/new/project-template.js +++ b/lib/commands/new/project-template.js @@ -110,6 +110,12 @@ exports.ProjectTemplate = class { } this.addToContent( + ProjectItem.directory('Properties').add( + ProjectItem.resource('launchSettings.json', 'content/javascriptservices/Properties/launchSettings.json').skipIfExists() + ), + ProjectItem.directory('Models').add( + ProjectItem.resource('ErrorViewModel.cs', 'content/javascriptservices/Models/ErrorViewModel.cs').skipIfExists() + ), ProjectItem.directory('Controllers').add( ProjectItem.resource('HomeController.cs', 'content/javascriptservices/Controllers/HomeController.cs').skipIfExists() ), @@ -141,6 +147,7 @@ exports.ProjectTemplate = class { this.content ), ProjectItem.resource('appsettings.json', 'content/javascriptservices/appsettings.json').skipIfExists(), + ProjectItem.resource('appsettings.Development.json', 'content/javascriptservices/appsettings.Development.json').skipIfExists(), ProjectItem.resource('global.json', 'content/javascriptservices/global.json').skipIfExists(), ProjectItem.resource('webpack.netcore.config.js', 'content/javascriptservices/webpack.netcore.config.js').skipIfExists() ); diff --git a/lib/resources/content/javascriptservices/Controllers/HomeController.cs b/lib/resources/content/javascriptservices/Controllers/HomeController.cs index 9d75da882..5f737f480 100644 --- a/lib/resources/content/javascriptservices/Controllers/HomeController.cs +++ b/lib/resources/content/javascriptservices/Controllers/HomeController.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using WebApplicationBasic.Models; namespace WebApplicationBasic.Controllers { @@ -13,9 +15,10 @@ public IActionResult Index() return View(); } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { - return View(); + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } } diff --git a/lib/resources/content/javascriptservices/Models/ErrorViewModel.cs b/lib/resources/content/javascriptservices/Models/ErrorViewModel.cs new file mode 100644 index 000000000..eee1a026d --- /dev/null +++ b/lib/resources/content/javascriptservices/Models/ErrorViewModel.cs @@ -0,0 +1,11 @@ +using System; + +namespace WebApplicationBasic.Models +{ + public class ErrorViewModel + { + public string RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } +} diff --git a/lib/resources/content/javascriptservices/Program.cs b/lib/resources/content/javascriptservices/Program.cs index 660cf684d..8ce09db2e 100644 --- a/lib/resources/content/javascriptservices/Program.cs +++ b/lib/resources/content/javascriptservices/Program.cs @@ -5,6 +5,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; namespace WebApplicationBasic { @@ -12,12 +14,11 @@ public class Program { public static void Main(string[] args) { - BuildWebHost(args).Run(); + CreateWebHostBuilder(args).Build().Run(); } - public static IWebHost BuildWebHost(string[] args) => + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) - .UseStartup() - .Build(); + .UseStartup(); } } diff --git a/lib/resources/content/javascriptservices/Properties/launchSettings.json b/lib/resources/content/javascriptservices/Properties/launchSettings.json new file mode 100644 index 000000000..0dde1cbe8 --- /dev/null +++ b/lib/resources/content/javascriptservices/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:63439/", + "sslPort": 44330 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "project": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/lib/resources/content/javascriptservices/Startup.cs b/lib/resources/content/javascriptservices/Startup.cs index 589d8f4b0..25183ce9e 100644 --- a/lib/resources/content/javascriptservices/Startup.cs +++ b/lib/resources/content/javascriptservices/Startup.cs @@ -4,10 +4,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; namespace WebApplicationBasic { @@ -24,12 +26,12 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - // Add framework services. - services.AddMvc(); + // Add framework services. + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } // 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) { if (env.IsDevelopment()) { @@ -46,8 +48,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF else { app.UseExceptionHandler("/Home/Error"); + app.UseHsts(); } + app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseMvc(routes => @@ -56,7 +60,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF name: "default", template: "{controller=Home}/{action=Index}/{id?}"); - routes.MapSpaFallbackRoute( + routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); diff --git a/lib/resources/content/javascriptservices/Startup.cs.readme.txt b/lib/resources/content/javascriptservices/Startup.cs.readme.txt index de23540c8..af13950c4 100644 --- a/lib/resources/content/javascriptservices/Startup.cs.readme.txt +++ b/lib/resources/content/javascriptservices/Startup.cs.readme.txt @@ -1,4 +1,4 @@ -If you're not yet using ASP.NET Core 2.0 (or don't have the Microsoft.AspNetCore.All package installed) then you need to install JavascriptServices. +If you're not yet using ASP.NET Core 2.1 (or don't have the Microsoft.AspNetCore.App package installed) then you need to install JavascriptServices. This can be done through the following command: "dotnet add package Microsoft.AspNetCore.SpaServices". Afterwards, open the Startup.cs file and add the following "using" statement at the top of the file: @@ -22,8 +22,10 @@ if (env.IsDevelopment()) else { app.UseExceptionHandler("/Home/Error"); + app.UseHsts(); } +app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseMvc(routes => @@ -42,18 +44,19 @@ Then, in the ConfigureServices method, make sure that the application uses Mvc: public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } + That's it for the Startup.cs file. If you're using Typescript then it's necessary to instruct Visual Studio not to transpile Typescript. This can be done by opening up the .csproj file. In this .csproj file you need to specify a TypeScriptToolsVersion and TypeScriptCompileBlocked like so: - netcoreapp2.0 + netcoreapp2.1 true Latest -That's it for the .csproj file. \ No newline at end of file +That's it for the .csproj file. diff --git a/lib/resources/content/javascriptservices/Views/Home/Index.cshtml b/lib/resources/content/javascriptservices/Views/Home/Index.cshtml index 038889390..4ff5cfbde 100644 --- a/lib/resources/content/javascriptservices/Views/Home/Index.cshtml +++ b/lib/resources/content/javascriptservices/Views/Home/Index.cshtml @@ -5,15 +5,16 @@
Loading...
@section scripts { + + + + + + - - - - - - - + + - + } diff --git a/lib/resources/content/javascriptservices/Views/Home/Index.cshtml.readme.txt b/lib/resources/content/javascriptservices/Views/Home/Index.cshtml.readme.txt index bf266125e..e78e643dc 100644 --- a/lib/resources/content/javascriptservices/Views/Home/Index.cshtml.readme.txt +++ b/lib/resources/content/javascriptservices/Views/Home/Index.cshtml.readme.txt @@ -7,17 +7,18 @@ Take a look at Views/Home/Index.cshtml and make sure that it contains the follow
Loading...
@section scripts { + + + + + + - - - - - - - + + - + } -That's it for Index.cshtml \ No newline at end of file +That's it for Index.cshtml diff --git a/lib/resources/content/javascriptservices/Views/Shared/Error.cshtml b/lib/resources/content/javascriptservices/Views/Shared/Error.cshtml index 473b35d6c..ac334e994 100644 --- a/lib/resources/content/javascriptservices/Views/Shared/Error.cshtml +++ b/lib/resources/content/javascriptservices/Views/Shared/Error.cshtml @@ -1,6 +1,22 @@ +@model ErrorViewModel @{ ViewData["Title"] = "Error"; }

Error.

An error occurred while processing your request.

+ +@if (Model.ShowRequestId) +{ +

+ Request ID: @Model.RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ Development environment should not be enabled in deployed applications, 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 ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. +

diff --git a/lib/resources/content/javascriptservices/Views/_ViewImports.cshtml b/lib/resources/content/javascriptservices/Views/_ViewImports.cshtml index e7b4f83fd..3d405ddff 100644 --- a/lib/resources/content/javascriptservices/Views/_ViewImports.cshtml +++ b/lib/resources/content/javascriptservices/Views/_ViewImports.cshtml @@ -1,3 +1,4 @@ @using WebApplicationBasic +@using WebApplicationBasic.Models @addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper "*, Microsoft.AspNetCore.SpaServices" diff --git a/lib/resources/content/javascriptservices/appsettings.Development.json b/lib/resources/content/javascriptservices/appsettings.Development.json new file mode 100644 index 000000000..e203e9407 --- /dev/null +++ b/lib/resources/content/javascriptservices/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/lib/resources/content/javascriptservices/appsettings.json b/lib/resources/content/javascriptservices/appsettings.json index 723c096a8..def9159a7 100644 --- a/lib/resources/content/javascriptservices/appsettings.json +++ b/lib/resources/content/javascriptservices/appsettings.json @@ -1,10 +1,8 @@ { "Logging": { - "IncludeScopes": false, "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning" } - } + }, + "AllowedHosts": "*" } diff --git a/lib/resources/content/javascriptservices/global.json b/lib/resources/content/javascriptservices/global.json index 1aa0d20aa..aa09f9d88 100644 --- a/lib/resources/content/javascriptservices/global.json +++ b/lib/resources/content/javascriptservices/global.json @@ -1,3 +1,3 @@ { - "sdk": { "version": "2.0.0" } + "sdk": { "version": "2.1.500" } } diff --git a/lib/resources/content/javascriptservices/project.csproject b/lib/resources/content/javascriptservices/project.csproject index 21fa277b5..3da0345f3 100644 --- a/lib/resources/content/javascriptservices/project.csproject +++ b/lib/resources/content/javascriptservices/project.csproject @@ -1,13 +1,13 @@ - netcoreapp2.0 + netcoreapp2.1 true Latest false - - + + @@ -16,9 +16,6 @@ - - -