zoukankan      html  css  js  c++  java
  • webapi core2.1 Identity.EntityFramework Core进行配置和操作数据 (一)没什么用

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual-studio%2Caspnetcore2x  的实践

    微软无api 的 identity 配置,专门写一篇关于 vs code 的配置

    dotnet new webapi -o Demo
    cd demo
    dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore

    Startup.cs

    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Identity;
    using Microsoft.EntityFrameworkCore;
    using Demo.Data;

    ->ConfigureServices

     services.Configure<CookiePolicyOptions>(options =>
                {
                    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                    options.CheckConsentNeeded = context => true;
                    options.MinimumSameSitePolicy = SameSiteMode.None;
                });
    
                services.AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(
                        Configuration.GetConnectionString("DefaultConnection")));
                services.AddDefaultIdentity<IdentityUser>()
                    .AddEntityFrameworkStores<ApplicationDbContext>();

    Data->ApplicationDbContext.cs 新建文件夹及文件

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
    using Microsoft.EntityFrameworkCore;
    
    namespace Demo.Data
    {
        public class ApplicationDbContext : IdentityDbContext
        {
            public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
                : base(options)
            {
            }
        }
    }

    appsettings.json 加入数据库连接

      "ConnectionStrings": {
        "DefaultConnection": "Server=(localdb)\mssqllocaldb;Database=aspnet-ids-3D54E4B2-38C1-466C-A12F-E9CCF493B11B;Trusted_Connection=True;MultipleActiveResultSets=true"
      },

    最后生成编译,

    生成数据库映射表

    更新数据库

    dotnet build
    dotnet ef migrations add Initial -o Data/Migrations
    dotnet ef database update
  • 相关阅读:
    Gym
    UVALive
    UVALive
    UVALive
    UVALive
    Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset Trie
    HDU 5816 Hearthstone 概率dp
    欧几里德与扩展欧几里德算法(转)
    差分约束系统详解(转)
    2016年第七届蓝桥杯C/C++程序设计本科B组决赛
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/9407428.html
Copyright © 2011-2022 走看看