From 5662dcc3ac99ed9c6f312818513264d223bfc762 Mon Sep 17 00:00:00 2001 From: Janak Shrestha Date: Fri, 1 Sep 2017 09:41:39 +0545 Subject: [PATCH] Upgraded to .Net Core 2.0 --- NetCoreSaaS.Core/NetCoreSaaS.Core.csproj | 2 +- .../Entities/Tenant/TenantUser.cs | 2 +- NetCoreSaaS.Data/NetCoreSaaS.Data.csproj | 10 +++---- NetCoreSaaS.Model/NetCoreSaaS.Model.csproj | 2 +- .../NetCoreSaaS.Service.csproj | 2 +- .../Controllers/AccountController.cs | 9 ++---- .../Controllers/ManageController.cs | 10 +++---- .../Extensions/DbContextExtension.cs | 6 ++-- .../Extensions/ServiceCollectionExtensions.cs | 4 +-- .../ManageViewModels/ManageLoginsViewModel.cs | 3 +- .../NetCoreSaaS.WebHost.csproj | 28 ++++++------------- NetCoreSaaS.WebHost/Program.cs | 20 ++++++------- NetCoreSaaS.WebHost/Services/IEmailSender.cs | 5 +--- NetCoreSaaS.WebHost/Services/ISmsSender.cs | 5 +--- .../Services/MessageServices.cs | 5 +--- NetCoreSaaS.WebHost/Startup.cs | 18 +++--------- .../Views/Account/Login.cshtml | 4 +-- NetCoreSaaS.sln | 15 ++++++---- 18 files changed, 58 insertions(+), 92 deletions(-) diff --git a/NetCoreSaaS.Core/NetCoreSaaS.Core.csproj b/NetCoreSaaS.Core/NetCoreSaaS.Core.csproj index 9dde595..eb7e066 100644 --- a/NetCoreSaaS.Core/NetCoreSaaS.Core.csproj +++ b/NetCoreSaaS.Core/NetCoreSaaS.Core.csproj @@ -1,7 +1,7 @@  - netstandard1.6 + netstandard2.0 \ No newline at end of file diff --git a/NetCoreSaaS.Data/Entities/Tenant/TenantUser.cs b/NetCoreSaaS.Data/Entities/Tenant/TenantUser.cs index fb0ebe2..aa2c75f 100644 --- a/NetCoreSaaS.Data/Entities/Tenant/TenantUser.cs +++ b/NetCoreSaaS.Data/Entities/Tenant/TenantUser.cs @@ -1,6 +1,6 @@ using System; using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.AspNetCore.Identity; namespace NetCoreSaaS.Data.Entities.Tenant { diff --git a/NetCoreSaaS.Data/NetCoreSaaS.Data.csproj b/NetCoreSaaS.Data/NetCoreSaaS.Data.csproj index 269a66a..b0d17e9 100644 --- a/NetCoreSaaS.Data/NetCoreSaaS.Data.csproj +++ b/NetCoreSaaS.Data/NetCoreSaaS.Data.csproj @@ -1,14 +1,14 @@  - netstandard1.6 + netstandard2.0 - - - - + + + + \ No newline at end of file diff --git a/NetCoreSaaS.Model/NetCoreSaaS.Model.csproj b/NetCoreSaaS.Model/NetCoreSaaS.Model.csproj index 9dde595..eb7e066 100644 --- a/NetCoreSaaS.Model/NetCoreSaaS.Model.csproj +++ b/NetCoreSaaS.Model/NetCoreSaaS.Model.csproj @@ -1,7 +1,7 @@  - netstandard1.6 + netstandard2.0 \ No newline at end of file diff --git a/NetCoreSaaS.Service/NetCoreSaaS.Service.csproj b/NetCoreSaaS.Service/NetCoreSaaS.Service.csproj index 9dde595..eb7e066 100644 --- a/NetCoreSaaS.Service/NetCoreSaaS.Service.csproj +++ b/NetCoreSaaS.Service/NetCoreSaaS.Service.csproj @@ -1,7 +1,7 @@  - netstandard1.6 + netstandard2.0 \ No newline at end of file diff --git a/NetCoreSaaS.WebHost/Controllers/AccountController.cs b/NetCoreSaaS.WebHost/Controllers/AccountController.cs index 1479a83..9dee4dd 100644 --- a/NetCoreSaaS.WebHost/Controllers/AccountController.cs +++ b/NetCoreSaaS.WebHost/Controllers/AccountController.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; @@ -8,13 +7,12 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using NetCoreSaaS.Core.ENums; using NetCoreSaaS.Data.Entities.Catalog; using NetCoreSaaS.Data.Entities.Tenant; -using NetCoreSaaS.WebHost.Models; using NetCoreSaaS.WebHost.Models.AccountViewModels; using NetCoreSaaS.WebHost.Services; +using Microsoft.AspNetCore.Authentication; namespace NetCoreSaaS.WebHost.Controllers { @@ -27,12 +25,10 @@ public class AccountController : Controller private readonly Tenant _currentTenant; private readonly ISmsSender _smsSender; private readonly ILogger _logger; - private readonly string _externalCookieScheme; public AccountController( UserManager userManager, SignInManager signInManager, - IOptions identityCookieOptions, IEmailSender emailSender, Tenant currentTenant, ISmsSender smsSender, @@ -40,7 +36,6 @@ public class AccountController : Controller { _userManager = userManager; _signInManager = signInManager; - _externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme; _emailSender = emailSender; _currentTenant = currentTenant; _smsSender = smsSender; @@ -54,7 +49,7 @@ public class AccountController : Controller public async Task Login(string returnUrl = null) { // Clear the existing external cookie to ensure a clean login process - await HttpContext.Authentication.SignOutAsync(_externalCookieScheme); + await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); ViewData["ReturnUrl"] = returnUrl; return View(); diff --git a/NetCoreSaaS.WebHost/Controllers/ManageController.cs b/NetCoreSaaS.WebHost/Controllers/ManageController.cs index b010351..f281f29 100644 --- a/NetCoreSaaS.WebHost/Controllers/ManageController.cs +++ b/NetCoreSaaS.WebHost/Controllers/ManageController.cs @@ -11,6 +11,7 @@ using NetCoreSaaS.WebHost.Models; using NetCoreSaaS.WebHost.Models.ManageViewModels; using NetCoreSaaS.WebHost.Services; +using Microsoft.AspNetCore.Authentication; namespace NetCoreSaaS.WebHost.Controllers { @@ -19,7 +20,6 @@ public class ManageController : Controller { private readonly UserManager _userManager; private readonly SignInManager _signInManager; - private readonly string _externalCookieScheme; private readonly IEmailSender _emailSender; private readonly ISmsSender _smsSender; private readonly ILogger _logger; @@ -27,14 +27,12 @@ public class ManageController : Controller public ManageController( UserManager userManager, SignInManager signInManager, - IOptions identityCookieOptions, IEmailSender emailSender, ISmsSender smsSender, ILoggerFactory loggerFactory) { _userManager = userManager; _signInManager = signInManager; - _externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme; _emailSender = emailSender; _smsSender = smsSender; _logger = loggerFactory.CreateLogger(); @@ -292,7 +290,7 @@ public async Task ManageLogins(ManageMessageId? message = null) return View("Error"); } var userLogins = await _userManager.GetLoginsAsync(user); - var otherLogins = _signInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList(); + var otherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).Where(auth => userLogins.All(ul => auth.Name != ul.LoginProvider)).ToList(); ViewData["ShowRemoveButton"] = user.PasswordHash != null || userLogins.Count > 1; return View(new ManageLoginsViewModel { @@ -308,7 +306,7 @@ public async Task ManageLogins(ManageMessageId? message = null) public async Task LinkLogin(string provider) { // Clear the existing external cookie to ensure a clean login process - await HttpContext.Authentication.SignOutAsync(_externalCookieScheme); + await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); // Request a redirect to the external login provider to link a login for the current user var redirectUrl = Url.Action(nameof(LinkLoginCallback), "Manage"); @@ -337,7 +335,7 @@ public async Task LinkLoginCallback() { message = ManageMessageId.AddLoginSuccess; // Clear the existing external cookie to ensure a clean login process - await HttpContext.Authentication.SignOutAsync(_externalCookieScheme); + await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); } return RedirectToAction(nameof(ManageLogins), new { Message = message }); } diff --git a/NetCoreSaaS.WebHost/Infrastructures/Extensions/DbContextExtension.cs b/NetCoreSaaS.WebHost/Infrastructures/Extensions/DbContextExtension.cs index 8d325c9..20ab068 100644 --- a/NetCoreSaaS.WebHost/Infrastructures/Extensions/DbContextExtension.cs +++ b/NetCoreSaaS.WebHost/Infrastructures/Extensions/DbContextExtension.cs @@ -8,7 +8,7 @@ namespace NetCoreSaaS.WebHost.Infrastructures.Extensions public static class DbContextExtension { - public static IServiceCollection AddSystemDataContext(this IServiceCollection services, IConfigurationRoot configuration, string migrationAssembly) + public static IServiceCollection AddSystemDataContext(this IServiceCollection services, IConfiguration configuration, string migrationAssembly) { services.AddDbContext(builder => builder.UseSqlServer(configuration.GetConnectionString("SystemConnection"), @@ -17,7 +17,7 @@ public static IServiceCollection AddSystemDataContext(this IServiceCollection se } - public static IServiceCollection AddCustomerDataContext(this IServiceCollection services, IConfigurationRoot configuration, string migrationAssembly) + public static IServiceCollection AddCustomerDataContext(this IServiceCollection services, IConfiguration configuration, string migrationAssembly) { services.AddDbContext(builder => builder.UseSqlServer(configuration.GetConnectionString("CatalogConnection"), @@ -26,7 +26,7 @@ public static IServiceCollection AddCustomerDataContext(this IServiceCollection } - public static IServiceCollection AddTenantDbContext(this IServiceCollection services, IConfigurationRoot configuration, string migrationAssembly) + public static IServiceCollection AddTenantDbContext(this IServiceCollection services, IConfiguration configuration, string migrationAssembly) { services.AddDbContext(); diff --git a/NetCoreSaaS.WebHost/Infrastructures/Extensions/ServiceCollectionExtensions.cs b/NetCoreSaaS.WebHost/Infrastructures/Extensions/ServiceCollectionExtensions.cs index 694edb0..2d38b01 100644 --- a/NetCoreSaaS.WebHost/Infrastructures/Extensions/ServiceCollectionExtensions.cs +++ b/NetCoreSaaS.WebHost/Infrastructures/Extensions/ServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NetCoreSaaS.Data.Contexts; @@ -21,7 +21,7 @@ public static IServiceCollection AddIdentityService(this IServiceCollection serv } - public static IServiceCollection AddContexts(this IServiceCollection services, IConfigurationRoot configuration, string migrationsAssembly) + public static IServiceCollection AddContexts(this IServiceCollection services, IConfiguration configuration, string migrationsAssembly) { services.AddSystemDataContext(configuration, migrationsAssembly) diff --git a/NetCoreSaaS.WebHost/Models/ManageViewModels/ManageLoginsViewModel.cs b/NetCoreSaaS.WebHost/Models/ManageViewModels/ManageLoginsViewModel.cs index 82cbd96..a879b81 100644 --- a/NetCoreSaaS.WebHost/Models/ManageViewModels/ManageLoginsViewModel.cs +++ b/NetCoreSaaS.WebHost/Models/ManageViewModels/ManageLoginsViewModel.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Authentication; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Authentication; namespace NetCoreSaaS.WebHost.Models.ManageViewModels { @@ -11,6 +12,6 @@ public class ManageLoginsViewModel { public IList CurrentLogins { get; set; } - public IList OtherLogins { get; set; } + public IList OtherLogins { get; set; } } } diff --git a/NetCoreSaaS.WebHost/NetCoreSaaS.WebHost.csproj b/NetCoreSaaS.WebHost/NetCoreSaaS.WebHost.csproj index 406a1e2..38af756 100644 --- a/NetCoreSaaS.WebHost/NetCoreSaaS.WebHost.csproj +++ b/NetCoreSaaS.WebHost/NetCoreSaaS.WebHost.csproj @@ -1,38 +1,26 @@  - netcoreapp1.1 + netcoreapp2.0 - $(PackageTargetFallback);portable-net45+win8+wp8+wpa81; + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; aspnet-NetCoreSaaS.WebHost-4d87baca-42fd-437d-84a4-10e94130fc5f + NetCoreSaaS.WebHost + NetCoreSaaS.WebHost - - - - - - - - - - - - - - - + - - - + + + diff --git a/NetCoreSaaS.WebHost/Program.cs b/NetCoreSaaS.WebHost/Program.cs index 57c724e..5586927 100644 --- a/NetCoreSaaS.WebHost/Program.cs +++ b/NetCoreSaaS.WebHost/Program.cs @@ -1,5 +1,4 @@ -using System.IO; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; namespace NetCoreSaaS.WebHost { @@ -7,15 +6,16 @@ public class Program { public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseKestrel() - .UseUrls("http://*.localhost:6001") - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseStartup() - .Build(); + BuildWebHost(args).Run(); + } - host.Run(); + public static IWebHost BuildWebHost(string[] args) + { + return Microsoft.AspNetCore.WebHost.CreateDefaultBuilder(args) + .UseUrls("http://*.localhost:6001") + .UseStartup() + .Build(); } } + } diff --git a/NetCoreSaaS.WebHost/Services/IEmailSender.cs b/NetCoreSaaS.WebHost/Services/IEmailSender.cs index 36b627a..2802f9d 100644 --- a/NetCoreSaaS.WebHost/Services/IEmailSender.cs +++ b/NetCoreSaaS.WebHost/Services/IEmailSender.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace NetCoreSaaS.WebHost.Services { diff --git a/NetCoreSaaS.WebHost/Services/ISmsSender.cs b/NetCoreSaaS.WebHost/Services/ISmsSender.cs index 7321015..5e05f24 100644 --- a/NetCoreSaaS.WebHost/Services/ISmsSender.cs +++ b/NetCoreSaaS.WebHost/Services/ISmsSender.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace NetCoreSaaS.WebHost.Services { diff --git a/NetCoreSaaS.WebHost/Services/MessageServices.cs b/NetCoreSaaS.WebHost/Services/MessageServices.cs index 01f84e0..45f603e 100644 --- a/NetCoreSaaS.WebHost/Services/MessageServices.cs +++ b/NetCoreSaaS.WebHost/Services/MessageServices.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace NetCoreSaaS.WebHost.Services { diff --git a/NetCoreSaaS.WebHost/Startup.cs b/NetCoreSaaS.WebHost/Startup.cs index 23b9de5..9af98a3 100644 --- a/NetCoreSaaS.WebHost/Startup.cs +++ b/NetCoreSaaS.WebHost/Startup.cs @@ -1,35 +1,25 @@ using System.Reflection; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NetCoreSaaS.Data.Contexts; using NetCoreSaaS.Data.Entities.Catalog; -using NetCoreSaaS.Data.Entities.Tenant; using NetCoreSaaS.WebHost.Infrastructures.Extensions; using NetCoreSaaS.WebHost.Infrastructures.Helpers.DbHelper; using NetCoreSaaS.WebHost.Infrastructures.TenantResolver; -using NetCoreSaaS.WebHost.Models; using NetCoreSaaS.WebHost.Services; namespace NetCoreSaaS.WebHost { public class Startup { - public Startup(IHostingEnvironment env) + public Startup(IConfiguration configuration) { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); - - builder.AddEnvironmentVariables(); - Configuration = builder.Build(); + Configuration = configuration; } - public IConfigurationRoot Configuration { get; } + public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { @@ -66,7 +56,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF app.UseStaticFiles(); app.UseMultitenancy(); - app.UseIdentity(); + app.UseAuthentication(); DbInitailizer.InitializeDatabase(app); app.UseMvc(routes => diff --git a/NetCoreSaaS.WebHost/Views/Account/Login.cshtml b/NetCoreSaaS.WebHost/Views/Account/Login.cshtml index 85006d0..b7bc35d 100644 --- a/NetCoreSaaS.WebHost/Views/Account/Login.cshtml +++ b/NetCoreSaaS.WebHost/Views/Account/Login.cshtml @@ -56,7 +56,7 @@

Use another service to log in.


@{ - var loginProviders = SignInManager.GetExternalAuthenticationSchemes().ToList(); + var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (loginProviders.Count == 0) {
@@ -73,7 +73,7 @@

@foreach (var provider in loginProviders) { - + }

diff --git a/NetCoreSaaS.sln b/NetCoreSaaS.sln index 15da152..4970633 100644 --- a/NetCoreSaaS.sln +++ b/NetCoreSaaS.sln @@ -1,17 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.6 +VisualStudioVersion = 15.0.26730.3 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreSaaS.WebHost", "NetCoreSaaS.WebHost\NetCoreSaaS.WebHost.csproj", "{68085211-D042-4E1B-ABDD-F6D23E7F5E72}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreSaaS.WebHost", "NetCoreSaaS.WebHost\NetCoreSaaS.WebHost.csproj", "{68085211-D042-4E1B-ABDD-F6D23E7F5E72}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreSaaS.Data", "NetCoreSaaS.Data\NetCoreSaaS.Data.csproj", "{33A282BF-85AD-42E1-A67C-B31043C5FB46}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreSaaS.Data", "NetCoreSaaS.Data\NetCoreSaaS.Data.csproj", "{33A282BF-85AD-42E1-A67C-B31043C5FB46}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreSaaS.Service", "NetCoreSaaS.Service\NetCoreSaaS.Service.csproj", "{3B4C4769-99F6-4B2C-9A5E-CBE9986299A6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreSaaS.Service", "NetCoreSaaS.Service\NetCoreSaaS.Service.csproj", "{3B4C4769-99F6-4B2C-9A5E-CBE9986299A6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreSaaS.Model", "NetCoreSaaS.Model\NetCoreSaaS.Model.csproj", "{7838CA7E-2AAD-47BA-B56A-B54D40D738A3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreSaaS.Model", "NetCoreSaaS.Model\NetCoreSaaS.Model.csproj", "{7838CA7E-2AAD-47BA-B56A-B54D40D738A3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreSaaS.Core", "NetCoreSaaS.Core\NetCoreSaaS.Core.csproj", "{5127E2EC-541D-4C96-A5F9-9EA1B347912C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreSaaS.Core", "NetCoreSaaS.Core\NetCoreSaaS.Core.csproj", "{5127E2EC-541D-4C96-A5F9-9EA1B347912C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,4 +43,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A3C0D690-E3A5-4E0C-9102-A62A46924671} + EndGlobalSection EndGlobal