Skip to content

Commit 8a3a4c3

Browse files
authored
ASP.NET Core 2 upgrade (#14)
1 parent 0ee8b40 commit 8a3a4c3

File tree

7 files changed

+25
-64
lines changed

7 files changed

+25
-64
lines changed
Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
55
<PreserveCompilationContext>true</PreserveCompilationContext>
66
<AssemblyName>Contacts</AssemblyName>
77
<OutputType>Exe</OutputType>
88
<PackageId>Contacts</PackageId>
99
<UserSecretsId>aspnet-Contacts-cd2c7b27-e79c-43c7-b3ef-1ecb04374b70</UserSecretsId>
10-
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
11-
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
10+
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
11+
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81</AssetTargetFallback>
1212
</PropertyGroup>
1313

1414
<ItemGroup>
@@ -18,30 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
22-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
23-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.1" />
24-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
25-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
26-
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
27-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
28-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
29-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
30-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1">
31-
<PrivateAssets>All</PrivateAssets>
32-
</PackageReference>
33-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
34-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
35-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
36-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
37-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
38-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
39-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
40-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
41-
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
42-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0">
43-
<PrivateAssets>All</PrivateAssets>
44-
</PackageReference>
21+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
4522
<PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />
4623
<PackageReference Include="BundlerMinifier.Core" Version="2.4.337" />
4724
</ItemGroup>
@@ -52,9 +29,9 @@
5229
</Target>
5330

5431
<ItemGroup>
55-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
56-
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0" />
57-
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
32+
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
33+
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
34+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
5835
</ItemGroup>
5936

6037
</Project>

ASP.NET Core Basics/src/Contacts/Controllers/ManageController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public async Task<IActionResult> ManageLogins(ManageMessageId? message = null)
287287
return View("Error");
288288
}
289289
var userLogins = await _userManager.GetLoginsAsync(user);
290-
var otherLogins = _signInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList();
290+
var otherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).Where(auth => userLogins.All(ul => auth.Name != ul.LoginProvider)).ToList();
291291
ViewData["ShowRemoveButton"] = user.PasswordHash != null || userLogins.Count > 1;
292292
return View(new ManageLoginsViewModel
293293
{

ASP.NET Core Basics/src/Contacts/Models/ApplicationUser.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
1+
using Microsoft.AspNetCore.Identity;
62

73
namespace Contacts.Models
84
{
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Http.Authentication;
1+
using System.Collections.Generic;
2+
using Microsoft.AspNetCore.Authentication;
63
using Microsoft.AspNetCore.Identity;
74

85
namespace Contacts.Models.ManageViewModels
@@ -11,6 +8,6 @@ public class ManageLoginsViewModel
118
{
129
public IList<UserLoginInfo> CurrentLogins { get; set; }
1310

14-
public IList<AuthenticationDescription> OtherLogins { get; set; }
11+
public IList<AuthenticationScheme> OtherLogins { get; set; }
1512
}
1613
}
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
1+
using Microsoft.AspNetCore;
62
using Microsoft.AspNetCore.Hosting;
73

84
namespace Contacts
@@ -11,14 +7,12 @@ public class Program
117
{
128
public static void Main(string[] args)
139
{
14-
var host = new WebHostBuilder()
15-
.UseKestrel()
16-
.UseContentRoot(Directory.GetCurrentDirectory())
17-
.UseIISIntegration()
18-
.UseStartup<Startup>()
19-
.Build();
20-
21-
host.Run();
10+
BuildWebHost(args).Run();
2211
}
12+
13+
public static IWebHost BuildWebHost(string[] args) =>
14+
WebHost.CreateDefaultBuilder(args)
15+
.UseStartup<Startup>()
16+
.Build();
2317
}
2418
}

ASP.NET Core Basics/src/Contacts/Startup.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
62
using Microsoft.AspNetCore.Hosting;
7-
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
83
using Microsoft.EntityFrameworkCore;
94
using Microsoft.Extensions.Configuration;
105
using Microsoft.Extensions.DependencyInjection;
116
using Microsoft.Extensions.Logging;
127
using Contacts.Data;
138
using Contacts.Models;
149
using Contacts.Services;
10+
using Microsoft.AspNetCore.Identity;
1511

1612
namespace Contacts
1713
{
@@ -78,7 +74,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
7874

7975
app.UseStaticFiles();
8076

81-
app.UseIdentity();
77+
app.UseAuthentication();
8278

8379
app.UseCors(builder =>
8480
{

ASP.NET Core Basics/src/Contacts/Views/Account/Login.cshtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using System.Collections.Generic
2+
@using System.Linq
23
@using Microsoft.AspNetCore.Http
34
@using Microsoft.AspNetCore.Http.Authentication
45
@model LoginViewModel
@@ -59,7 +60,7 @@
5960
<h4>Use another service to log in.</h4>
6061
<hr />
6162
@{
62-
var loginProviders = SignInManager.GetExternalAuthenticationSchemes().ToList();
63+
var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList();
6364
if (loginProviders.Count == 0)
6465
{
6566
<div>
@@ -76,7 +77,7 @@
7677
<p>
7778
@foreach (var provider in loginProviders)
7879
{
79-
<button type="submit" class="btn btn-default" name="provider" value="@provider.AuthenticationScheme" title="Log in using your @provider.DisplayName account">@provider.AuthenticationScheme</button>
80+
<button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.Name</button>
8081
}
8182
</p>
8283
</div>

0 commit comments

Comments
 (0)