Skip to content

Commit ec00582

Browse files
committed
Upgrade to .Net Core 2.2
1 parent 3fbf349 commit ec00582

File tree

79 files changed

+27349
-11174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+27349
-11174
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

dotnetcore-sample.sln

Lines changed: 0 additions & 28 deletions
This file was deleted.

dotnetcore-sample/.bowerrc

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using System.Threading.Tasks;
56
using Microsoft.AspNetCore.Mvc;
7+
using dotnetcore_sample.Models;
68

79
namespace dotnetcore_sample.Controllers
810
{
@@ -13,23 +15,15 @@ public IActionResult Index()
1315
return View();
1416
}
1517

16-
public IActionResult About()
18+
public IActionResult Privacy()
1719
{
18-
ViewData["Message"] = "Your application description page.";
19-
20-
return View();
21-
}
22-
23-
public IActionResult Contact()
24-
{
25-
ViewData["Message"] = "Your contact page.";
26-
2720
return View();
2821
}
2922

23+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
3024
public IActionResult Error()
3125
{
32-
return View();
26+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
3327
}
3428
}
3529
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace dotnetcore_sample.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}

dotnetcore-sample/Program.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
67
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
710

811
namespace dotnetcore_sample
912
{
1013
public class Program
1114
{
1215
public static void Main(string[] args)
1316
{
14-
var host = new WebHostBuilder()
15-
.UseKestrel()
16-
.UseContentRoot(Directory.GetCurrentDirectory())
17-
.UseIISIntegration()
18-
.UseStartup<Startup>()
19-
.UseApplicationInsights()
20-
.Build();
21-
22-
host.Run();
17+
CreateWebHostBuilder(args).Build().Run();
2318
}
19+
20+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>();
2423
}
2524
}

dotnetcore-sample/Startup.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,54 @@
44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Builder;
66
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.AspNetCore.HttpsPolicy;
9+
using Microsoft.AspNetCore.Mvc;
710
using Microsoft.Extensions.Configuration;
811
using Microsoft.Extensions.DependencyInjection;
9-
using Microsoft.Extensions.Logging;
10-
using System.Reflection;
11-
using System.IO;
1212

1313
namespace dotnetcore_sample
1414
{
1515
public class Startup
1616
{
17-
public Startup(IHostingEnvironment env)
17+
public Startup(IConfiguration configuration)
1818
{
19-
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
20-
string appSettingsFilePath = Path.Combine(assemblyFolder,"appsettings.json");
21-
22-
var builder = new ConfigurationBuilder()
23-
.SetBasePath(env.ContentRootPath)
24-
.AddJsonFile(appSettingsFilePath, optional: false, reloadOnChange: true)
25-
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
26-
.AddEnvironmentVariables();
27-
Configuration = builder.Build();
19+
Configuration = configuration;
2820
}
2921

30-
public IConfigurationRoot Configuration { get; }
22+
public IConfiguration Configuration { get; }
3123

3224
// This method gets called by the runtime. Use this method to add services to the container.
3325
public void ConfigureServices(IServiceCollection services)
3426
{
35-
// Add framework services.
36-
services.AddMvc();
27+
services.Configure<CookiePolicyOptions>(options =>
28+
{
29+
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
30+
options.CheckConsentNeeded = context => true;
31+
options.MinimumSameSitePolicy = SameSiteMode.None;
32+
});
33+
34+
35+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
3736
}
3837

3938
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
40-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
39+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
4140
{
42-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
43-
loggerFactory.AddDebug();
44-
4541
if (env.IsDevelopment())
4642
{
4743
app.UseDeveloperExceptionPage();
48-
app.UseBrowserLink();
4944
}
5045
else
5146
{
5247
app.UseExceptionHandler("/Home/Error");
48+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
49+
app.UseHsts();
5350
}
5451

52+
app.UseHttpsRedirection();
5553
app.UseStaticFiles();
54+
app.UseCookiePolicy();
5655

5756
app.UseMvc(routes =>
5857
{

dotnetcore-sample/Views/Home/About.cshtml

Lines changed: 0 additions & 7 deletions
This file was deleted.

dotnetcore-sample/Views/Home/Contact.cshtml

Lines changed: 0 additions & 17 deletions
This file was deleted.

dotnetcore-sample/Views/Home/Index.cshtml

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,7 @@
22
ViewData["Title"] = "Home Page";
33
}
44

5-
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="6000">
6-
<ol class="carousel-indicators">
7-
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
8-
<li data-target="#myCarousel" data-slide-to="1"></li>
9-
<li data-target="#myCarousel" data-slide-to="2"></li>
10-
<li data-target="#myCarousel" data-slide-to="3"></li>
11-
</ol>
12-
<div class="carousel-inner" role="listbox">
13-
<div class="item active">
14-
<img src="~/images/banner1.svg" alt="ASP.NET" class="img-responsive" />
15-
<div class="carousel-caption" role="option">
16-
<p>
17-
Learn how to build ASP.NET apps that can run anywhere.
18-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525028&clcid=0x409">
19-
Learn More
20-
</a>
21-
</p>
22-
</div>
23-
</div>
24-
<div class="item">
25-
<img src="~/images/banner2.svg" alt="Visual Studio" class="img-responsive" />
26-
<div class="carousel-caption" role="option">
27-
<p>
28-
There are powerful new features in Visual Studio for building modern web apps.
29-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525030&clcid=0x409">
30-
Learn More
31-
</a>
32-
</p>
33-
</div>
34-
</div>
35-
<div class="item">
36-
<img src="~/images/banner3.svg" alt="Package Management" class="img-responsive" />
37-
<div class="carousel-caption" role="option">
38-
<p>
39-
Bring in libraries from NuGet, Bower, and npm, and automate tasks using Grunt or Gulp.
40-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525029&clcid=0x409">
41-
Learn More
42-
</a>
43-
</p>
44-
</div>
45-
</div>
46-
<div class="item">
47-
<img src="~/images/banner4.svg" alt="Microsoft Azure" class="img-responsive" />
48-
<div class="carousel-caption" role="option">
49-
<p>
50-
Learn how Microsoft's Azure cloud platform allows you to build, deploy, and scale web apps.
51-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525027&clcid=0x409">
52-
Learn More
53-
</a>
54-
</p>
55-
</div>
56-
</div>
57-
</div>
58-
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
59-
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
60-
<span class="sr-only">Previous</span>
61-
</a>
62-
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
63-
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
64-
<span class="sr-only">Next</span>
65-
</a>
66-
</div>
67-
68-
<div class="row">
69-
<div class="col-md-3">
70-
<h2>Application uses</h2>
71-
<ul>
72-
<li>Sample pages using ASP.NET Core MVC</li>
73-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=518004">Bower</a> for managing client-side libraries</li>
74-
<li>Theming using <a href="https://go.microsoft.com/fwlink/?LinkID=398939">Bootstrap</a></li>
75-
</ul>
76-
</div>
77-
<div class="col-md-3">
78-
<h2>How to</h2>
79-
<ul>
80-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=398600">Add a Controller and View</a></li>
81-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699315">Manage User Secrets using Secret Manager.</a></li>
82-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699316">Use logging to log a message.</a></li>
83-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699317">Add packages using NuGet.</a></li>
84-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699318">Add client packages using Bower.</a></li>
85-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699319">Target development, staging or production environment.</a></li>
86-
</ul>
87-
</div>
88-
<div class="col-md-3">
89-
<h2>Overview</h2>
90-
<ul>
91-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=518008">Conceptual overview of what is ASP.NET Core</a></li>
92-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699320">Fundamentals of ASP.NET Core such as Startup and middleware.</a></li>
93-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=398602">Working with Data</a></li>
94-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=398603">Security</a></li>
95-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699321">Client side development</a></li>
96-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699322">Develop on different platforms</a></li>
97-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699323">Read more on the documentation site</a></li>
98-
</ul>
99-
</div>
100-
<div class="col-md-3">
101-
<h2>Run & Deploy</h2>
102-
<ul>
103-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=517851">Run your app</a></li>
104-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=517853">Run tools such as EF migrations and more</a></li>
105-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=398609">Publish to Microsoft Azure Web Apps</a></li>
106-
</ul>
107-
</div>
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome</h1>
7+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
1088
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
@{
1+
@model ErrorViewModel
2+
@{
23
ViewData["Title"] = "Error";
34
}
45

56
<h1 class="text-danger">Error.</h1>
67
<h2 class="text-danger">An error occurred while processing your request.</h2>
78

9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
816
<h3>Development Mode</h3>
917
<p>
1018
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
1119
</p>
1220
<p>
13-
<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.
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
1425
</p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@using Microsoft.AspNetCore.Http.Features
2+
3+
@{
4+
var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
5+
var showBanner = !consentFeature?.CanTrack ?? false;
6+
var cookieString = consentFeature?.CreateConsentCookie();
7+
}
8+
9+
@if (showBanner)
10+
{
11+
<div id="cookieConsent" class="alert alert-info alert-dismissible fade show" role="alert">
12+
Use this space to summarize your privacy and cookie use policy. <a asp-area="" asp-controller="Home" asp-action="Privacy">Learn More</a>.
13+
<button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
14+
<span aria-hidden="true">Accept</span>
15+
</button>
16+
</div>
17+
<script>
18+
(function () {
19+
var button = document.querySelector("#cookieConsent button[data-cookie-string]");
20+
button.addEventListener("click", function (event) {
21+
document.cookie = button.dataset.cookieString;
22+
}, false);
23+
})();
24+
</script>
25+
}

0 commit comments

Comments
 (0)