Asp identitas inti bersih mysql

Akhirnya, Anda ingin membatasi akses ke beberapa/semua halaman di situs Anda. Aplikasi .NET Core MVC, jadi setiap orang harus memasukkan login dan kata sandi mereka terlebih dahulu (mengotentikasi diri mereka sendiri), dan kemudian server akan memutuskan apakah akan membiarkan mereka membuka halaman atau tidak (mengotorisasi akses)

Manual resmi memandu Anda melalui proses dengan cukup baik, namun hanya menceritakan tentang pengaturannya dengan MS SQL Server. Tapi kami, tentu saja, ingin menggunakan MySQL untuk itu

Saya mencoba menggunakan MySQL dengan. NET Core Identity sebelumnya, tetapi ada yang salah dengan dukungannya saat itu, dan sekarang benar-benar berfungsi (kurang lebih)

Mengapa menggunakan Identitas sama sekali?

NET Inti 2. 0

Sebelum kita mulai, inilah versi namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_0 saya untuk berjaga-jaga

$ dotnet --info .NET Command Line Tools (2.1.4) Product Information: Version: 2.1.4 Commit SHA-1 hash: 5e8add2190 Runtime Environment: OS Name: Mac OS X OS Version: 10.13 OS Platform: Darwin RID: osx.10.12-x64 Base Path: /usr/local/share/dotnet/sdk/2.1.4/ Microsoft .NET Core Shared Framework Host Version : 2.0.5 Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54

Dengan asumsi Anda telah menggunakan template dengan autentikasi/otorisasi using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }9 bawaan (namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }2), saya akan melewatkan pengontrol, model, dan tampilan. Jika Anda sudah memiliki proyek yang sudah ada dan ingin menambahkannya di sana, maka tidak masalah, buat saja yang baru menggunakan template ini dan cukup salin model dan tampilannya ke proyek Anda

Instal paket NuGet berikut

  • namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_3 (2. 0. 2);
  • namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_4 (2. 0. 2);
  • namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_5 (6. 10. 6);
  • namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_6 (6. 10. 6)

Itu adalah versi yang saya miliki, tetapi kemungkinan besar versi lain juga akan baik-baik saja

Tambahkan string koneksi ke database Anda di namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }7

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }

Tambahkan namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_8 kelas ke proyek Anda, namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }9

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }

Saya tidak membuat kelas public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }_0 saya sendiri, karena saya memutuskan untuk mengambil default public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }1, jadi saya menggantinya di views public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }2 dan public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }3 dan juga mengubah konstruktor public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }4 (dan public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }5) sebagai berikut

namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_

Aktifkan using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_9 autentikasi/otorisasi di public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }7

public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }

Beberapa kata (lumpuh) tentang Entity Framework. using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_9 dapat menggunakan berbagai penyimpanan untuk penggunanya/kata sandi/peran/informasi apa pun. Disini kita menggunakan database MySQL. Dan dengan menggunakan apa yang disebut pendekatan kode-pertama Entity Framework menghasilkan pernyataan SQL dari using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }9 model C # internal (tabel untuk pengguna, peran, dll dan hubungan di antara mereka). Proses menghasilkan pernyataan ini dan menerapkannya ke database disebut migrasi. Setidaknya begitulah cara saya memahami prosesnya, jadi lebih baik baca beberapa buku tentang masalah ini

Kami memiliki model using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_9 kami siap untuk migrasi, jadi mari kita lakukan satu. Pastikan Anda memiliki namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }0 versi dotnet ef migrations add InitialCreate2 dan bukan dotnet ef migrations add InitialCreate3, dan juga Anda berada di direktori dengan dotnet ef migrations add InitialCreate4. Jalankan perintah ini

dotnet ef migrations add InitialCreate

Kemungkinan besar Anda akan mendapatkan kesalahan berikut

No executable found matching command "dotnet-ef"

Solusi untuk itu ditemukan di (dan tempat lain). pastikan Anda memiliki baris berikut di dotnet ef migrations add InitialCreate4

<ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>

Jalankan dotnet ef migrations add InitialCreate_6. Milik saya gagal dengan kesalahan ini

error MSB4024: The imported project file "project/obj/project.csproj.EntityFrameworkCore.targets" could not be loaded. Unexpected end tag.

Saya membuka file, menghapus tag "tak terduga" ini, dan membersihkan serta membangun kembali proyek (untuk berjaga-jaga)

Setelah melakukan itu, coba periksa alat EF

$ dotnet ef _/\__ ---==/ \\ ___ ___ |. \|\ | __|| __| | ) \\\ | _| | _| \_/ | //|\\ |___||_| / \\\/\\ Entity Framework Core .NET Command Line Tools 2.0.0-rtm-26452 Usage: dotnet ef [options] [command] Options: --version Show version information -h|--help Show help information -v|--verbose Show verbose output. --no-color Don't colorize output. --prefix-output Prefix output with level. Commands: database Commands to manage the database. dbcontext Commands to manage DbContext types. migrations Commands to manage migrations. Use "dotnet ef [command] --help" for more information about a command.

Oke. Sekarang lakukan migrasi awal Anda (hentikan debugging jika Anda menjalankannya di Visual Studio, jika tidak, Anda akan mendapatkan kesalahan dotnet ef migrations add InitialCreate7)

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_0

Bagus. Anda harus mendapatkan file berikut yang dihasilkan

  • dotnet ef migrations add InitialCreate8;
  • dotnet ef migrations add InitialCreate_9;
  • No executable found matching command "dotnet-ef"_0

Terapkan migrasi ini ke database

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_1

…Setidaknya, cobalah. Karena bagi saya itu menghasilkan banyak kesalahan

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_2

Dari jawaban ini saya mendapatkan bahwa MySQL (atau siapa pun) belum mendukung migrasi dengan benar, jadi Anda perlu membuat tabel ini secara manual (melalui No executable found matching command "dotnet-ef"1 atau DBMS pilihan Anda)

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_3

Setelah menjalankan No executable found matching command "dotnet-ef"_2 setelah itu, saya mendapat kesalahan baru

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_4

Yang ini terjadi karena di suatu tempat di MySQL EF (atau di mana pun) ada beberapa kekacauan dengan kunci komposit, sehingga panjang totalnya melebihi batas. Saya berharap itu akan diperbaiki di masa depan, tetapi sementara ini ada a. edit namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_9 Anda

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_5

Sekarang Anda akhirnya dapat menjalankan No executable found matching command "dotnet-ef"_2 dan itu akan membuat semua tabel yang diperlukan tanpa masalah (setidaknya, itu terjadi untuk saya). Inilah tabel yang harus Anda dapatkan

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_6

Jika Anda ingin mengembalikan migrasi untuk melakukan yang baru, coba jalankan No executable found matching command "dotnet-ef"5 atau cukup hapus file dari No executable found matching command "dotnet-ef"6. Tapi itu tidak akan menyentuh tabel setengah jadi di database, jadi Anda harus menghapusnya secara manual

Bagian migrasi selesai. Namun, Anda mungkin mendapatkan kesalahan berikut setelah mencoba menjalankan aplikasi Anda

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_7

Kemungkinan besar, Anda menambahkan using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }9 tampilan dan model ke proyek yang sudah ada dan lupa menyalin konten No executable found matching command "dotnet-ef"8

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_8

Sekarang semuanya akan baik-baik saja

Jadi, bagaimana cara menggunakannya?

Anda sudah menggunakannya. Semua tindakan pengontrol Anda sekarang mengharuskan pengguna untuk masuk

Mungkin, Anda ingin agar tindakan No executable found matching command "dotnet-ef"9 tersedia untuk umum, karena kemungkinan besar itulah yang menangani halaman utama dan juga halaman kesalahan dalam proyek Anda. Jika demikian, tambahkan atribut <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>0 ke seluruh controller

"ConnectionStrings": { "DefaultConnection": "server=localhost;port=3306;database=some;user=some;password=some;CharSet=utf8;" }_9

Hal yang sama berlaku untuk tindakan <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>1 dari public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }4, jika tidak, tidak ada yang dapat masuk ke situs web Anda. Untuk melakukannya, tambahkan atribut <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>_0 ke tindakan, sehingga akan tersedia untuk pengguna anonim

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }0

Dan ketika pengguna mencoba membuka halaman yang mengharuskan dia untuk mengautentikasi dirinya sendiri (tindakan tanpa atribut <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>0), aplikasi Anda akan menampilkan halaman login kepadanya

Seperti yang sudah saya sebutkan, using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }9 hadir dengan dukungan peran di luar kotak, sehingga Anda dapat mengontrol akses bahkan untuk pengguna yang sudah masuk berdasarkan peran mereka. Misalnya, tindakan berikut hanya tersedia untuk pengguna dengan peran <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>6

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_1

Dan terima kasih kepada using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_9, Anda diberikan semua yang Anda butuhkan untuk mengelola peran. Misalnya, jika Anda membuka halaman <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>8 (atau hanya <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>9) di browser Anda, Anda akan melihat sesuatu seperti ini

Anda dapat mendaftarkan pengguna baru, menghapus yang sudah ada dan mengontrol peran yang mereka miliki. Dan ada juga tampilan untuk membuat/menghapus peran

Jadi, menggunakan. NET Core Identity dengan database MySQL sangat memungkinkan, meskipun prosesnya secara keseluruhan masih memiliki beberapa masalah

[19. 10. 2018] Pembaruan. Migrasi ke. NET Inti 2. 1

NET Inti 2. 1

Jadi,. NET Inti 2. 1 dirilis

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_2

… dan tentu saja itu merusak beberapa hal. Sementara beberapa dapat diperbaiki dengan mengikuti manual migrasi, MySQL EntityFramework dari Oracle rusak untuk selamanya

Misalnya, saya mendapat kesalahan berikut (juga dicatat oleh seseorang di komentar) setelah memperbarui ke. NET Inti 2. 1

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_3

Googling kesalahan saya menemukan utas ini, dari mana saya mendapatkan laporan bug ini di pelacak Oracle, yang pada dasarnya mengatakan bahwa Oracle tidak memberikan tikus terbang tentang memperbaikinya

Tapi kabar baiknya Yayasan Pomelo melakukannya, dan mereka benar-benar memperbaiki masalah dalam paket mereka, jadi solusinya adalah menyerah pada Oracle dan beralih ke Pomelo

Mari kita lihat pada contoh proyek baru yang dibuat dari awal

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_4

Ubah string koneksi di namespace YOUR-PROJECT-NAMESPACE.Controllers { public class AccountController : Controller { private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; private readonly SignInManager<IdentityUser> _signInManager; private readonly ILogger _logger; private readonly IdentityContext _context; private readonly IConfiguration _configuration; public AccountController( UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<IdentityUser> signInManager, ILoggerFactory loggerFactory, IdentityContext context, IConfiguration configuration ) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger<AccountController>(); _context = context; _configuration = configuration; } // ... } }_7

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }5

Dan melakukan migrasi

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }6

Itu akan membuat sesuatu seperti ini di database Anda

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_7

Kemudian ubah dari error MSB4024: The imported project file "project/obj/project.csproj.EntityFrameworkCore.targets" could not be loaded. Unexpected end tag.1 menjadi error MSB4024: The imported project file "project/obj/project.csproj.EntityFrameworkCore.targets" could not be loaded. Unexpected end tag.2 di public void ConfigureServices(IServiceCollection services) { // that's where you tell that you want to use MySQL services.AddDbContext<IdentityContext>( options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityContext>(); services.Configure<IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequireLowercase = true; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }); // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; options.ExpireTimeSpan = TimeSpan.FromDays(150); }); services.AddMvc( options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); // ... } ); // ... } public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { // ... app.UseAuthentication(); // ... }7

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace YOUR-PROJECT-NAMESPACE.Data { public class IdentityContext : IdentityDbContext<IdentityUser> { public IdentityContext(DbContextOptions<IdentityContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } }_8

Dan itu saja, bahkan tidak perlu mengganti error MSB4024: The imported project file "project/obj/project.csproj.EntityFrameworkCore.targets" could not be loaded. Unexpected end tag.4 dengan kustomisasi tipe data yang aneh itu - semuanya berjalan begitu saja di luar kotak

Untuk apa identitas inti Aspnet digunakan?

ASP. Identitas Inti NET. Adalah API yang mendukung fungsi masuk antarmuka pengguna (UI) . Mengelola pengguna, kata sandi, data profil, peran, klaim, token, konfirmasi email, dan lainnya.

Bagaimana cara membuat tabel identitas net asp di dalam database yang ada?

Dalam artikel ini .
Mulailah dengan ASP. Identitas BERSIH
Tambahkan paket Identitas ke aplikasi Anda
Tambahkan formulir web untuk mendaftarkan pengguna
Verifikasi database dan tabel LocalDb Identity yang dihasilkan oleh Entity Framework
Konfigurasikan aplikasi untuk otentikasi OWIN
Instal paket autentikasi ke aplikasi Anda

Apa itu UI identitas Microsoft Aspnetcore?

ASP. NET Core Identity adalah sistem keanggotaan untuk membangun ASP. Aplikasi web .NET Core, termasuk keanggotaan, login, dan data pengguna . ASP. NET Core Identity memungkinkan Anda menambahkan fitur login ke aplikasi Anda dan memudahkan penyesuaian data tentang pengguna yang login.

Apakah identitas ASP NET gratis?

IdentityServer adalah OpenID Connect dan OAuth 2 open source gratis. 0 kerangka kerja untuk ASP. .NET Core .

Postingan terbaru

LIHAT SEMUA