diff --git a/vs4win/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj b/vs4win/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj index 8f873a5..cff975c 100644 --- a/vs4win/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj +++ b/vs4win/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj @@ -10,4 +10,9 @@ + + + + + diff --git a/vs4win/PracticalApps/Minimal.WebApi/Properties/launchSettings.json b/vs4win/PracticalApps/Minimal.WebApi/Properties/launchSettings.json index 2137b19..af47987 100644 --- a/vs4win/PracticalApps/Minimal.WebApi/Properties/launchSettings.json +++ b/vs4win/PracticalApps/Minimal.WebApi/Properties/launchSettings.json @@ -9,11 +9,21 @@ } }, "profiles": { - "Minimal.WebApi": { + "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "weatherforecast", + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", "applicationUrl": "https://localhost:5003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/vs4win/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico b/vs4win/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vs4win/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico differ diff --git a/vs4win/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj b/vs4win/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj index a3ec562..c5f3964 100644 --- a/vs4win/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj +++ b/vs4win/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj @@ -6,6 +6,14 @@ enable + + + + + + + + diff --git a/vs4win/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj.user b/vs4win/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/vs4win/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/vs4win/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json b/vs4win/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json index 87e09fc..4899f05 100644 --- a/vs4win/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json +++ b/vs4win/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json @@ -8,7 +8,16 @@ } }, "profiles": { - "Northwind.BlazorServer": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5004", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/vs4win/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico b/vs4win/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico index 63e859b..46d8f40 100644 Binary files a/vs4win/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico and b/vs4win/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico differ diff --git a/vs4win/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico b/vs4win/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico index 63e859b..46d8f40 100644 Binary files a/vs4win/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico and b/vs4win/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico differ diff --git a/vs4win/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json b/vs4win/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json index c272881..dd8a802 100644 --- a/vs4win/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json +++ b/vs4win/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json @@ -1,30 +1,38 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:36368", - "sslPort": 44354 + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:36368", + "sslPort": 44354 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5006", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } }, - "profiles": { - "Northwind.BlazorWasm.Server": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:5007;http://localhost:5006", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:5007;http://localhost:5006", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } } } +} diff --git a/vs4win/PracticalApps/Northwind.BlazorWasm/Server/wwwroot/favicon.ico b/vs4win/PracticalApps/Northwind.BlazorWasm/Server/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vs4win/PracticalApps/Northwind.BlazorWasm/Server/wwwroot/favicon.ico differ diff --git a/vs4win/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs b/vs4win/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs index afabb0c..068b4a9 100644 --- a/vs4win/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs +++ b/vs4win/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs @@ -75,14 +75,16 @@ namespace Northwind.Mvc.Controllers return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } - public async Task ProductDetail(int? id) + public async Task ProductDetail(int? id, string alertstyle = "success") { + ViewData["alertstyle"] = alertstyle; + if (!id.HasValue) { return BadRequest("You must pass a product ID in the route, for example, /Home/ProductDetail/21"); } - Product? model = await db.Products + Product? model = await db.Products.Include(p => p.Category) .SingleOrDefaultAsync(p => p.ProductId == id); if (model is null) diff --git a/vs4win/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs b/vs4win/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs index bc7c762..f399edc 100644 --- a/vs4win/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs +++ b/vs4win/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs @@ -25,7 +25,7 @@ public class RolesController : Controller { await roleManager.CreateAsync(new IdentityRole(AdminRole)); } - IdentityUser user = await userManager.FindByEmailAsync(UserEmail); + IdentityUser? user = await userManager.FindByEmailAsync(UserEmail); if (user == null) { diff --git a/vs4win/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj b/vs4win/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj index c78c3b2..8a25b34 100644 --- a/vs4win/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj +++ b/vs4win/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj @@ -5,7 +5,11 @@ enable enable aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5 - + + + preview + true + @@ -25,9 +29,14 @@ - + + + + + + true + PreserveNewest + diff --git a/vs4win/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj.user b/vs4win/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj.user new file mode 100644 index 0000000..80ee073 --- /dev/null +++ b/vs4win/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj.user @@ -0,0 +1,9 @@ + + + + ProjectDebugger + + + https + + \ No newline at end of file diff --git a/vs4win/PracticalApps/Northwind.Mvc/Program.cs b/vs4win/PracticalApps/Northwind.Mvc/Program.cs index f504bd2..536c399 100644 --- a/vs4win/PracticalApps/Northwind.Mvc/Program.cs +++ b/vs4win/PracticalApps/Northwind.Mvc/Program.cs @@ -38,6 +38,12 @@ else // if you are using SQLite default is ..\Northwind.db builder.Services.AddNorthwindContext(); +builder.Services.AddOutputCache(options => +{ + options.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(20); + options.AddPolicy("views", p => p.VaryByQuery("")); +}); + builder.Services.AddHttpClient(name: "Northwind.WebApi", configureClient: options => { @@ -77,16 +83,23 @@ else app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); +app.UseOutputCache(); + app.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Home}/{action=Index}/{id?}") + .CacheOutput("views"); + app.MapRazorPages(); +app.MapGet("/notcached", () => DateTime.Now.ToString()); + +app.MapGet("/cached", () => DateTime.Now.ToString()).CacheOutput(); + // Section 4 - start the host web server listening for HTTP requests app.Run(); diff --git a/vs4win/PracticalApps/Northwind.Mvc/Properties/launchSettings.json b/vs4win/PracticalApps/Northwind.Mvc/Properties/launchSettings.json index cf08137..878352d 100644 --- a/vs4win/PracticalApps/Northwind.Mvc/Properties/launchSettings.json +++ b/vs4win/PracticalApps/Northwind.Mvc/Properties/launchSettings.json @@ -8,7 +8,16 @@ } }, "profiles": { - "Northwind.Mvc": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/vs4win/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml b/vs4win/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml index 5e4ebce..f060f61 100644 --- a/vs4win/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml +++ b/vs4win/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml @@ -3,6 +3,8 @@ ViewData["Title"] = "Product Detail - " + Model.ProductName; }

Product Detail

+

+ @DateTime.Now.ToLongTimeString()


@@ -10,8 +12,8 @@
@Model.ProductId
Product Name
@Model.ProductName
-
Category Id
-
@Model.CategoryId
+
Category
+
@Model.CategoryId - @Model.Category.CategoryName
Unit Price
@Model.UnitPrice.Value.ToString("C")
Units In Stock
diff --git a/vs4win/PracticalApps/Northwind.Mvc/appsettings.Development.json b/vs4win/PracticalApps/Northwind.Mvc/appsettings.Development.json index 0c208ae..daa1dc0 100644 --- a/vs4win/PracticalApps/Northwind.Mvc/appsettings.Development.json +++ b/vs4win/PracticalApps/Northwind.Mvc/appsettings.Development.json @@ -2,7 +2,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.AspNetCore.OutputCaching": "Information" } } } diff --git a/vs4win/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico b/vs4win/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico index 63e859b..46d8f40 100644 Binary files a/vs4win/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico and b/vs4win/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico differ diff --git a/vs4win/PracticalApps/Northwind.Web/Northwind.Web.csproj b/vs4win/PracticalApps/Northwind.Web/Northwind.Web.csproj index a4f7af1..372120c 100644 --- a/vs4win/PracticalApps/Northwind.Web/Northwind.Web.csproj +++ b/vs4win/PracticalApps/Northwind.Web/Northwind.Web.csproj @@ -10,6 +10,10 @@ true + + + + diff --git a/vs4win/PracticalApps/Northwind.Web/Northwind.Web.csproj.user b/vs4win/PracticalApps/Northwind.Web/Northwind.Web.csproj.user new file mode 100644 index 0000000..80ee073 --- /dev/null +++ b/vs4win/PracticalApps/Northwind.Web/Northwind.Web.csproj.user @@ -0,0 +1,9 @@ + + + + ProjectDebugger + + + https + + \ No newline at end of file diff --git a/vs4win/PracticalApps/Northwind.Web/Program.cs b/vs4win/PracticalApps/Northwind.Web/Program.cs index 46cadcb..6652eff 100644 --- a/vs4win/PracticalApps/Northwind.Web/Program.cs +++ b/vs4win/PracticalApps/Northwind.Web/Program.cs @@ -7,6 +7,9 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddNorthwindContext(); +builder.Services.AddRequestDecompression(); + +/* builder.WebHost.ConfigureKestrel((context, options) => { options.ListenAnyIP(5001, listenOptions => @@ -15,6 +18,7 @@ builder.WebHost.ConfigureKestrel((context, options) => listenOptions.UseHttps(); // HTTP/3 requires secure connections }); }); +*/ var app = builder.Build(); @@ -51,6 +55,8 @@ app.Use(async (HttpContext context, Func next) => app.UseHttpsRedirection(); +app.UseRequestDecompression(); + app.UseDefaultFiles(); // index.html, default.html, and so on app.UseStaticFiles(); diff --git a/vs4win/PracticalApps/Northwind.Web/Properties/launchSettings.json b/vs4win/PracticalApps/Northwind.Web/Properties/launchSettings.json index 69fd904..98e0dbb 100644 --- a/vs4win/PracticalApps/Northwind.Web/Properties/launchSettings.json +++ b/vs4win/PracticalApps/Northwind.Web/Properties/launchSettings.json @@ -8,7 +8,16 @@ } }, "profiles": { - "Northwind.Web": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/vs4win/PracticalApps/Northwind.Web/wwwroot/favicon.ico b/vs4win/PracticalApps/Northwind.Web/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vs4win/PracticalApps/Northwind.Web/wwwroot/favicon.ico differ diff --git a/vs4win/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj b/vs4win/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj index 73d280e..d7159bd 100644 --- a/vs4win/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj +++ b/vs4win/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj @@ -14,6 +14,7 @@ + diff --git a/vs4win/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj.user b/vs4win/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/vs4win/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/vs4win/PracticalApps/Northwind.WebApi/Program.cs b/vs4win/PracticalApps/Northwind.WebApi/Program.cs index b0e7fc0..3297665 100644 --- a/vs4win/PracticalApps/Northwind.WebApi/Program.cs +++ b/vs4win/PracticalApps/Northwind.WebApi/Program.cs @@ -38,8 +38,11 @@ builder.Services.AddSwaggerGen(); builder.Services.AddScoped(); builder.Services.AddHealthChecks() - .AddDbContextCheck(); + .AddDbContextCheck() + // execute SELECT 1 using the specified connection string + .AddSqlServer("Data Source=.;Initial Catalog=Northwind;Integrated Security=true;"); +/* builder.WebHost.ConfigureKestrel((context, options) => { options.ListenAnyIP(5002, listenOptions => @@ -48,6 +51,7 @@ builder.WebHost.ConfigureKestrel((context, options) => listenOptions.UseHttps(); // HTTP/3 requires secure connections }); }); +*/ var app = builder.Build(); diff --git a/vs4win/PracticalApps/Northwind.WebApi/Properties/launchSettings.json b/vs4win/PracticalApps/Northwind.WebApi/Properties/launchSettings.json index 2ced0db..3092c1d 100644 --- a/vs4win/PracticalApps/Northwind.WebApi/Properties/launchSettings.json +++ b/vs4win/PracticalApps/Northwind.WebApi/Properties/launchSettings.json @@ -9,10 +9,20 @@ } }, "profiles": { - "Northwind.WebApi": { + "http": { "commandName": "Project", "dotnetRunMessages": true, - "launchBrowser": false, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:5002", "environmentVariables": { diff --git a/vs4win/PracticalApps/Northwind.WebApi/appsettings.Development.json b/vs4win/PracticalApps/Northwind.WebApi/appsettings.Development.json index 0c208ae..3e805ed 100644 --- a/vs4win/PracticalApps/Northwind.WebApi/appsettings.Development.json +++ b/vs4win/PracticalApps/Northwind.WebApi/appsettings.Development.json @@ -2,7 +2,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information" } } } diff --git a/vs4win/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico b/vs4win/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vs4win/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico differ diff --git a/vs4win/PracticalApps/favicon_io.zip b/vs4win/PracticalApps/favicon_io.zip new file mode 100644 index 0000000..df7092a Binary files /dev/null and b/vs4win/PracticalApps/favicon_io.zip differ diff --git a/vscode/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj b/vscode/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj index 8f873a5..cff975c 100644 --- a/vscode/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj +++ b/vscode/PracticalApps/Minimal.WebApi/Minimal.WebApi.csproj @@ -10,4 +10,9 @@ + + + + + diff --git a/vscode/PracticalApps/Minimal.WebApi/Properties/launchSettings.json b/vscode/PracticalApps/Minimal.WebApi/Properties/launchSettings.json index 2137b19..af47987 100644 --- a/vscode/PracticalApps/Minimal.WebApi/Properties/launchSettings.json +++ b/vscode/PracticalApps/Minimal.WebApi/Properties/launchSettings.json @@ -9,11 +9,21 @@ } }, "profiles": { - "Minimal.WebApi": { + "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "weatherforecast", + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", "applicationUrl": "https://localhost:5003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/vscode/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico b/vscode/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vscode/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico differ diff --git a/vscode/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj b/vscode/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj index a3ec562..c5f3964 100644 --- a/vscode/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj +++ b/vscode/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj @@ -6,6 +6,14 @@ enable + + + + + + + + diff --git a/vscode/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj.user b/vscode/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/vscode/PracticalApps/Northwind.BlazorServer/Northwind.BlazorServer.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/vscode/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json b/vscode/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json index 87e09fc..4899f05 100644 --- a/vscode/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json +++ b/vscode/PracticalApps/Northwind.BlazorServer/Properties/launchSettings.json @@ -8,7 +8,16 @@ } }, "profiles": { - "Northwind.BlazorServer": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5004", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/vscode/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico b/vscode/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico index 63e859b..46d8f40 100644 Binary files a/vscode/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico and b/vscode/PracticalApps/Northwind.BlazorServer/wwwroot/favicon.ico differ diff --git a/vscode/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico b/vscode/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico index 63e859b..46d8f40 100644 Binary files a/vscode/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico and b/vscode/PracticalApps/Northwind.BlazorWasm/Client/wwwroot/favicon.ico differ diff --git a/vscode/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json b/vscode/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json index c272881..dd8a802 100644 --- a/vscode/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json +++ b/vscode/PracticalApps/Northwind.BlazorWasm/Server/Properties/launchSettings.json @@ -1,30 +1,38 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:36368", - "sslPort": 44354 + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:36368", + "sslPort": 44354 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5006", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } }, - "profiles": { - "Northwind.BlazorWasm.Server": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:5007;http://localhost:5006", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:5007;http://localhost:5006", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } } } +} diff --git a/vscode/PracticalApps/Northwind.BlazorWasm/Server/wwwroot/favicon.ico b/vscode/PracticalApps/Northwind.BlazorWasm/Server/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vscode/PracticalApps/Northwind.BlazorWasm/Server/wwwroot/favicon.ico differ diff --git a/vscode/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs b/vscode/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs index afabb0c..068b4a9 100644 --- a/vscode/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs +++ b/vscode/PracticalApps/Northwind.Mvc/Controllers/HomeController.cs @@ -75,14 +75,16 @@ namespace Northwind.Mvc.Controllers return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } - public async Task ProductDetail(int? id) + public async Task ProductDetail(int? id, string alertstyle = "success") { + ViewData["alertstyle"] = alertstyle; + if (!id.HasValue) { return BadRequest("You must pass a product ID in the route, for example, /Home/ProductDetail/21"); } - Product? model = await db.Products + Product? model = await db.Products.Include(p => p.Category) .SingleOrDefaultAsync(p => p.ProductId == id); if (model is null) diff --git a/vscode/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs b/vscode/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs index bc7c762..f399edc 100644 --- a/vscode/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs +++ b/vscode/PracticalApps/Northwind.Mvc/Controllers/RolesController.cs @@ -25,7 +25,7 @@ public class RolesController : Controller { await roleManager.CreateAsync(new IdentityRole(AdminRole)); } - IdentityUser user = await userManager.FindByEmailAsync(UserEmail); + IdentityUser? user = await userManager.FindByEmailAsync(UserEmail); if (user == null) { diff --git a/vscode/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj b/vscode/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj index c78c3b2..8a25b34 100644 --- a/vscode/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj +++ b/vscode/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj @@ -5,7 +5,11 @@ enable enable aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5 - + + + preview + true + @@ -25,9 +29,14 @@ - + + + + + + true + PreserveNewest + diff --git a/vscode/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj.user b/vscode/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj.user new file mode 100644 index 0000000..80ee073 --- /dev/null +++ b/vscode/PracticalApps/Northwind.Mvc/Northwind.Mvc.csproj.user @@ -0,0 +1,9 @@ + + + + ProjectDebugger + + + https + + \ No newline at end of file diff --git a/vscode/PracticalApps/Northwind.Mvc/Program.cs b/vscode/PracticalApps/Northwind.Mvc/Program.cs index f504bd2..536c399 100644 --- a/vscode/PracticalApps/Northwind.Mvc/Program.cs +++ b/vscode/PracticalApps/Northwind.Mvc/Program.cs @@ -38,6 +38,12 @@ else // if you are using SQLite default is ..\Northwind.db builder.Services.AddNorthwindContext(); +builder.Services.AddOutputCache(options => +{ + options.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(20); + options.AddPolicy("views", p => p.VaryByQuery("")); +}); + builder.Services.AddHttpClient(name: "Northwind.WebApi", configureClient: options => { @@ -77,16 +83,23 @@ else app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); +app.UseOutputCache(); + app.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Home}/{action=Index}/{id?}") + .CacheOutput("views"); + app.MapRazorPages(); +app.MapGet("/notcached", () => DateTime.Now.ToString()); + +app.MapGet("/cached", () => DateTime.Now.ToString()).CacheOutput(); + // Section 4 - start the host web server listening for HTTP requests app.Run(); diff --git a/vscode/PracticalApps/Northwind.Mvc/Properties/launchSettings.json b/vscode/PracticalApps/Northwind.Mvc/Properties/launchSettings.json index cf08137..878352d 100644 --- a/vscode/PracticalApps/Northwind.Mvc/Properties/launchSettings.json +++ b/vscode/PracticalApps/Northwind.Mvc/Properties/launchSettings.json @@ -8,7 +8,16 @@ } }, "profiles": { - "Northwind.Mvc": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/vscode/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml b/vscode/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml index 5e4ebce..f060f61 100644 --- a/vscode/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml +++ b/vscode/PracticalApps/Northwind.Mvc/Views/Home/ProductDetail.cshtml @@ -3,6 +3,8 @@ ViewData["Title"] = "Product Detail - " + Model.ProductName; }

Product Detail

+

+ @DateTime.Now.ToLongTimeString()


@@ -10,8 +12,8 @@
@Model.ProductId
Product Name
@Model.ProductName
-
Category Id
-
@Model.CategoryId
+
Category
+
@Model.CategoryId - @Model.Category.CategoryName
Unit Price
@Model.UnitPrice.Value.ToString("C")
Units In Stock
diff --git a/vscode/PracticalApps/Northwind.Mvc/appsettings.Development.json b/vscode/PracticalApps/Northwind.Mvc/appsettings.Development.json index 0c208ae..daa1dc0 100644 --- a/vscode/PracticalApps/Northwind.Mvc/appsettings.Development.json +++ b/vscode/PracticalApps/Northwind.Mvc/appsettings.Development.json @@ -2,7 +2,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.AspNetCore.OutputCaching": "Information" } } } diff --git a/vscode/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico b/vscode/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico index 63e859b..46d8f40 100644 Binary files a/vscode/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico and b/vscode/PracticalApps/Northwind.Mvc/wwwroot/favicon.ico differ diff --git a/vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj b/vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj index a4f7af1..372120c 100644 --- a/vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj +++ b/vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj @@ -10,6 +10,10 @@ true + + + + diff --git a/vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj.user b/vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj.user new file mode 100644 index 0000000..80ee073 --- /dev/null +++ b/vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj.user @@ -0,0 +1,9 @@ + + + + ProjectDebugger + + + https + + \ No newline at end of file diff --git a/vscode/PracticalApps/Northwind.Web/Program.cs b/vscode/PracticalApps/Northwind.Web/Program.cs index 46cadcb..6652eff 100644 --- a/vscode/PracticalApps/Northwind.Web/Program.cs +++ b/vscode/PracticalApps/Northwind.Web/Program.cs @@ -7,6 +7,9 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddNorthwindContext(); +builder.Services.AddRequestDecompression(); + +/* builder.WebHost.ConfigureKestrel((context, options) => { options.ListenAnyIP(5001, listenOptions => @@ -15,6 +18,7 @@ builder.WebHost.ConfigureKestrel((context, options) => listenOptions.UseHttps(); // HTTP/3 requires secure connections }); }); +*/ var app = builder.Build(); @@ -51,6 +55,8 @@ app.Use(async (HttpContext context, Func next) => app.UseHttpsRedirection(); +app.UseRequestDecompression(); + app.UseDefaultFiles(); // index.html, default.html, and so on app.UseStaticFiles(); diff --git a/vscode/PracticalApps/Northwind.Web/Properties/launchSettings.json b/vscode/PracticalApps/Northwind.Web/Properties/launchSettings.json index 69fd904..98e0dbb 100644 --- a/vscode/PracticalApps/Northwind.Web/Properties/launchSettings.json +++ b/vscode/PracticalApps/Northwind.Web/Properties/launchSettings.json @@ -8,7 +8,16 @@ } }, "profiles": { - "Northwind.Web": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, diff --git a/vscode/PracticalApps/Northwind.Web/wwwroot/favicon.ico b/vscode/PracticalApps/Northwind.Web/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vscode/PracticalApps/Northwind.Web/wwwroot/favicon.ico differ diff --git a/vscode/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj b/vscode/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj index 73d280e..d7159bd 100644 --- a/vscode/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj +++ b/vscode/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj @@ -14,6 +14,7 @@ + diff --git a/vscode/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj.user b/vscode/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/vscode/PracticalApps/Northwind.WebApi/Northwind.WebApi.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/vscode/PracticalApps/Northwind.WebApi/Program.cs b/vscode/PracticalApps/Northwind.WebApi/Program.cs index b0e7fc0..3297665 100644 --- a/vscode/PracticalApps/Northwind.WebApi/Program.cs +++ b/vscode/PracticalApps/Northwind.WebApi/Program.cs @@ -38,8 +38,11 @@ builder.Services.AddSwaggerGen(); builder.Services.AddScoped(); builder.Services.AddHealthChecks() - .AddDbContextCheck(); + .AddDbContextCheck() + // execute SELECT 1 using the specified connection string + .AddSqlServer("Data Source=.;Initial Catalog=Northwind;Integrated Security=true;"); +/* builder.WebHost.ConfigureKestrel((context, options) => { options.ListenAnyIP(5002, listenOptions => @@ -48,6 +51,7 @@ builder.WebHost.ConfigureKestrel((context, options) => listenOptions.UseHttps(); // HTTP/3 requires secure connections }); }); +*/ var app = builder.Build(); diff --git a/vscode/PracticalApps/Northwind.WebApi/Properties/launchSettings.json b/vscode/PracticalApps/Northwind.WebApi/Properties/launchSettings.json index 2ced0db..3092c1d 100644 --- a/vscode/PracticalApps/Northwind.WebApi/Properties/launchSettings.json +++ b/vscode/PracticalApps/Northwind.WebApi/Properties/launchSettings.json @@ -9,10 +9,20 @@ } }, "profiles": { - "Northwind.WebApi": { + "http": { "commandName": "Project", "dotnetRunMessages": true, - "launchBrowser": false, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:5002", "environmentVariables": { diff --git a/vscode/PracticalApps/Northwind.WebApi/appsettings.Development.json b/vscode/PracticalApps/Northwind.WebApi/appsettings.Development.json index 0c208ae..3e805ed 100644 --- a/vscode/PracticalApps/Northwind.WebApi/appsettings.Development.json +++ b/vscode/PracticalApps/Northwind.WebApi/appsettings.Development.json @@ -2,7 +2,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information" } } } diff --git a/vscode/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico b/vscode/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico new file mode 100644 index 0000000..46d8f40 Binary files /dev/null and b/vscode/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico differ diff --git a/vscode/PracticalApps/favicon_io.zip b/vscode/PracticalApps/favicon_io.zip new file mode 100644 index 0000000..df7092a Binary files /dev/null and b/vscode/PracticalApps/favicon_io.zip differ