Initial commit

This commit is contained in:
Mark J Price 2022-09-24 09:10:26 +01:00
parent 1da926d605
commit 638c6f8f2b
62 changed files with 372 additions and 90 deletions

View file

@ -10,4 +10,9 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<!-- change Sqlite to SqlServer if you prefer -->
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
</ItemGroup>
</Project> </Project>

View file

@ -9,11 +9,21 @@
} }
}, },
"profiles": { "profiles": {
"Minimal.WebApi": { "http": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": 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", "applicationUrl": "https://localhost:5003",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -6,6 +6,14 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Remove="wwwroot\favicon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\favicon.ico" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<!-- change Sqlite to SqlServer if you prefer --> <!-- change Sqlite to SqlServer if you prefer -->
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" /> <ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -8,7 +8,16 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.BlazorServer": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5004",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -8,11 +8,19 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.BlazorWasm.Server": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5006",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5007;http://localhost:5006", "applicationUrl": "https://localhost:5007;http://localhost:5006",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -75,14 +75,16 @@ namespace Northwind.Mvc.Controllers
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
public async Task<IActionResult> ProductDetail(int? id) public async Task<IActionResult> ProductDetail(int? id, string alertstyle = "success")
{ {
ViewData["alertstyle"] = alertstyle;
if (!id.HasValue) if (!id.HasValue)
{ {
return BadRequest("You must pass a product ID in the route, for example, /Home/ProductDetail/21"); 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); .SingleOrDefaultAsync(p => p.ProductId == id);
if (model is null) if (model is null)

View file

@ -25,7 +25,7 @@ public class RolesController : Controller
{ {
await roleManager.CreateAsync(new IdentityRole(AdminRole)); await roleManager.CreateAsync(new IdentityRole(AdminRole));
} }
IdentityUser user = await userManager.FindByEmailAsync(UserEmail); IdentityUser? user = await userManager.FindByEmailAsync(UserEmail);
if (user == null) if (user == null)
{ {

View file

@ -5,6 +5,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5</UserSecretsId> <UserSecretsId>aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5</UserSecretsId>
<!--remove the elements below after GA release-->
<LangVersion>preview</LangVersion>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -25,9 +29,14 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<RuntimeHostConfigurationOption <RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
Include="System.Net.SocketsHttpHandler.Http3Support" </ItemGroup>
Value="true" />
<ItemGroup>
<Content Update="wwwroot\favicon.ico">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -38,6 +38,12 @@ else
// if you are using SQLite default is ..\Northwind.db // if you are using SQLite default is ..\Northwind.db
builder.Services.AddNorthwindContext(); builder.Services.AddNorthwindContext();
builder.Services.AddOutputCache(options =>
{
options.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(20);
options.AddPolicy("views", p => p.VaryByQuery(""));
});
builder.Services.AddHttpClient(name: "Northwind.WebApi", builder.Services.AddHttpClient(name: "Northwind.WebApi",
configureClient: options => configureClient: options =>
{ {
@ -77,16 +83,23 @@ else
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseOutputCache();
app.MapControllerRoute( app.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}")
.CacheOutput("views");
app.MapRazorPages(); 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 // Section 4 - start the host web server listening for HTTP requests
app.Run(); app.Run();

View file

@ -8,7 +8,16 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.Mvc": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,

View file

@ -3,6 +3,8 @@
ViewData["Title"] = "Product Detail - " + Model.ProductName; ViewData["Title"] = "Product Detail - " + Model.ProductName;
} }
<h2>Product Detail</h2> <h2>Product Detail</h2>
<p class="alert alert-@ViewData["alertstyle"]">
@DateTime.Now.ToLongTimeString()</p>
<hr /> <hr />
<div> <div>
<dl class="dl-horizontal"> <dl class="dl-horizontal">
@ -10,8 +12,8 @@
<dd>@Model.ProductId</dd> <dd>@Model.ProductId</dd>
<dt>Product Name</dt> <dt>Product Name</dt>
<dd>@Model.ProductName</dd> <dd>@Model.ProductName</dd>
<dt>Category Id</dt> <dt>Category</dt>
<dd>@Model.CategoryId</dd> <dd>@Model.CategoryId - @Model.Category.CategoryName</dd>
<dt>Unit Price</dt> <dt>Unit Price</dt>
<dd>@Model.UnitPrice.Value.ToString("C")</dd> <dd>@Model.UnitPrice.Value.ToString("C")</dd>
<dt>Units In Stock</dt> <dt>Units In Stock</dt>

View file

@ -2,7 +2,8 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.OutputCaching": "Information"
} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -10,6 +10,10 @@
<EnablePreviewFeatures>true</EnablePreviewFeatures> <EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Include="wwwroot\favicon.ico" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Using Include="System.Console" Static="true" /> <Using Include="System.Console" Static="true" />
</ItemGroup> </ItemGroup>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -7,6 +7,9 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages(); builder.Services.AddRazorPages();
builder.Services.AddNorthwindContext(); builder.Services.AddNorthwindContext();
builder.Services.AddRequestDecompression();
/*
builder.WebHost.ConfigureKestrel((context, options) => builder.WebHost.ConfigureKestrel((context, options) =>
{ {
options.ListenAnyIP(5001, listenOptions => options.ListenAnyIP(5001, listenOptions =>
@ -15,6 +18,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
listenOptions.UseHttps(); // HTTP/3 requires secure connections listenOptions.UseHttps(); // HTTP/3 requires secure connections
}); });
}); });
*/
var app = builder.Build(); var app = builder.Build();
@ -51,6 +55,8 @@ app.Use(async (HttpContext context, Func<Task> next) =>
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseRequestDecompression();
app.UseDefaultFiles(); // index.html, default.html, and so on app.UseDefaultFiles(); // index.html, default.html, and so on
app.UseStaticFiles(); app.UseStaticFiles();

View file

@ -8,7 +8,16 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.Web": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.0-*" /> <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.0-*" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -38,8 +38,11 @@ builder.Services.AddSwaggerGen();
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>(); builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
builder.Services.AddHealthChecks() builder.Services.AddHealthChecks()
.AddDbContextCheck<NorthwindContext>(); .AddDbContextCheck<NorthwindContext>()
// execute SELECT 1 using the specified connection string
.AddSqlServer("Data Source=.;Initial Catalog=Northwind;Integrated Security=true;");
/*
builder.WebHost.ConfigureKestrel((context, options) => builder.WebHost.ConfigureKestrel((context, options) =>
{ {
options.ListenAnyIP(5002, listenOptions => options.ListenAnyIP(5002, listenOptions =>
@ -48,6 +51,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
listenOptions.UseHttps(); // HTTP/3 requires secure connections listenOptions.UseHttps(); // HTTP/3 requires secure connections
}); });
}); });
*/
var app = builder.Build(); var app = builder.Build();

View file

@ -9,10 +9,20 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.WebApi": { "http": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "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", "launchUrl": "swagger",
"applicationUrl": "https://localhost:5002", "applicationUrl": "https://localhost:5002",
"environmentVariables": { "environmentVariables": {

View file

@ -2,7 +2,8 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

View file

@ -10,4 +10,9 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<!-- change Sqlite to SqlServer if you prefer -->
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
</ItemGroup>
</Project> </Project>

View file

@ -9,11 +9,21 @@
} }
}, },
"profiles": { "profiles": {
"Minimal.WebApi": { "http": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": 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", "applicationUrl": "https://localhost:5003",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -6,6 +6,14 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Remove="wwwroot\favicon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\favicon.ico" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<!-- change Sqlite to SqlServer if you prefer --> <!-- change Sqlite to SqlServer if you prefer -->
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" /> <ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -8,7 +8,16 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.BlazorServer": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5004",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -8,11 +8,19 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.BlazorWasm.Server": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5006",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5007;http://localhost:5006", "applicationUrl": "https://localhost:5007;http://localhost:5006",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -75,14 +75,16 @@ namespace Northwind.Mvc.Controllers
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
public async Task<IActionResult> ProductDetail(int? id) public async Task<IActionResult> ProductDetail(int? id, string alertstyle = "success")
{ {
ViewData["alertstyle"] = alertstyle;
if (!id.HasValue) if (!id.HasValue)
{ {
return BadRequest("You must pass a product ID in the route, for example, /Home/ProductDetail/21"); 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); .SingleOrDefaultAsync(p => p.ProductId == id);
if (model is null) if (model is null)

View file

@ -25,7 +25,7 @@ public class RolesController : Controller
{ {
await roleManager.CreateAsync(new IdentityRole(AdminRole)); await roleManager.CreateAsync(new IdentityRole(AdminRole));
} }
IdentityUser user = await userManager.FindByEmailAsync(UserEmail); IdentityUser? user = await userManager.FindByEmailAsync(UserEmail);
if (user == null) if (user == null)
{ {

View file

@ -5,6 +5,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5</UserSecretsId> <UserSecretsId>aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5</UserSecretsId>
<!--remove the elements below after GA release-->
<LangVersion>preview</LangVersion>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -25,9 +29,14 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<RuntimeHostConfigurationOption <RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
Include="System.Net.SocketsHttpHandler.Http3Support" </ItemGroup>
Value="true" />
<ItemGroup>
<Content Update="wwwroot\favicon.ico">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -38,6 +38,12 @@ else
// if you are using SQLite default is ..\Northwind.db // if you are using SQLite default is ..\Northwind.db
builder.Services.AddNorthwindContext(); builder.Services.AddNorthwindContext();
builder.Services.AddOutputCache(options =>
{
options.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(20);
options.AddPolicy("views", p => p.VaryByQuery(""));
});
builder.Services.AddHttpClient(name: "Northwind.WebApi", builder.Services.AddHttpClient(name: "Northwind.WebApi",
configureClient: options => configureClient: options =>
{ {
@ -77,16 +83,23 @@ else
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseOutputCache();
app.MapControllerRoute( app.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}")
.CacheOutput("views");
app.MapRazorPages(); 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 // Section 4 - start the host web server listening for HTTP requests
app.Run(); app.Run();

View file

@ -8,7 +8,16 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.Mvc": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,

View file

@ -3,6 +3,8 @@
ViewData["Title"] = "Product Detail - " + Model.ProductName; ViewData["Title"] = "Product Detail - " + Model.ProductName;
} }
<h2>Product Detail</h2> <h2>Product Detail</h2>
<p class="alert alert-@ViewData["alertstyle"]">
@DateTime.Now.ToLongTimeString()</p>
<hr /> <hr />
<div> <div>
<dl class="dl-horizontal"> <dl class="dl-horizontal">
@ -10,8 +12,8 @@
<dd>@Model.ProductId</dd> <dd>@Model.ProductId</dd>
<dt>Product Name</dt> <dt>Product Name</dt>
<dd>@Model.ProductName</dd> <dd>@Model.ProductName</dd>
<dt>Category Id</dt> <dt>Category</dt>
<dd>@Model.CategoryId</dd> <dd>@Model.CategoryId - @Model.Category.CategoryName</dd>
<dt>Unit Price</dt> <dt>Unit Price</dt>
<dd>@Model.UnitPrice.Value.ToString("C")</dd> <dd>@Model.UnitPrice.Value.ToString("C")</dd>
<dt>Units In Stock</dt> <dt>Units In Stock</dt>

View file

@ -2,7 +2,8 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.OutputCaching": "Information"
} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -10,6 +10,10 @@
<EnablePreviewFeatures>true</EnablePreviewFeatures> <EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Include="wwwroot\favicon.ico" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Using Include="System.Console" Static="true" /> <Using Include="System.Console" Static="true" />
</ItemGroup> </ItemGroup>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -7,6 +7,9 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages(); builder.Services.AddRazorPages();
builder.Services.AddNorthwindContext(); builder.Services.AddNorthwindContext();
builder.Services.AddRequestDecompression();
/*
builder.WebHost.ConfigureKestrel((context, options) => builder.WebHost.ConfigureKestrel((context, options) =>
{ {
options.ListenAnyIP(5001, listenOptions => options.ListenAnyIP(5001, listenOptions =>
@ -15,6 +18,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
listenOptions.UseHttps(); // HTTP/3 requires secure connections listenOptions.UseHttps(); // HTTP/3 requires secure connections
}); });
}); });
*/
var app = builder.Build(); var app = builder.Build();
@ -51,6 +55,8 @@ app.Use(async (HttpContext context, Func<Task> next) =>
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseRequestDecompression();
app.UseDefaultFiles(); // index.html, default.html, and so on app.UseDefaultFiles(); // index.html, default.html, and so on
app.UseStaticFiles(); app.UseStaticFiles();

View file

@ -8,7 +8,16 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.Web": { "http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.0-*" /> <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.0-*" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>

View file

@ -38,8 +38,11 @@ builder.Services.AddSwaggerGen();
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>(); builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
builder.Services.AddHealthChecks() builder.Services.AddHealthChecks()
.AddDbContextCheck<NorthwindContext>(); .AddDbContextCheck<NorthwindContext>()
// execute SELECT 1 using the specified connection string
.AddSqlServer("Data Source=.;Initial Catalog=Northwind;Integrated Security=true;");
/*
builder.WebHost.ConfigureKestrel((context, options) => builder.WebHost.ConfigureKestrel((context, options) =>
{ {
options.ListenAnyIP(5002, listenOptions => options.ListenAnyIP(5002, listenOptions =>
@ -48,6 +51,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
listenOptions.UseHttps(); // HTTP/3 requires secure connections listenOptions.UseHttps(); // HTTP/3 requires secure connections
}); });
}); });
*/
var app = builder.Build(); var app = builder.Build();

View file

@ -9,10 +9,20 @@
} }
}, },
"profiles": { "profiles": {
"Northwind.WebApi": { "http": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "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", "launchUrl": "swagger",
"applicationUrl": "https://localhost:5002", "applicationUrl": "https://localhost:5002",
"environmentVariables": { "environmentVariables": {

View file

@ -2,7 +2,8 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.