發表文章

目前顯示的是 2018的文章

dotnet new sln

# Create the solution directory mkdir dotnet-identity-example cd dotnet-identity-example # Create the Web project using an empty webapi template dotnet new webapi --name Web # Create a solution file and add the web project to it dotnet new sln dotnet sln add Web/Web.csproj # Restore dependencies and run the project dotnet restore cd Web dotnet run

Identity Server WebAPI

圖片
DAL 安裝所需套件 install-package AutoMapper 新增 Models目錄 新增 ApplicationUser.cs using Microsoft.AspNetCore.Identity; public class ApplicationUser :IdentityUser { ...新增所需要之欄位 } 新增 Models目錄 新增 ApplicationRole.cs using Microsoft.AspNetCore.Identity; public class ApplicationRole :IdentityRole { ...新增所需要之欄位 } 專案目錄下 新增 ApplicationDbContext.cs using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; public class ApplicationDbContext :IdentityDbContext<ApplicationUser,ApplicationRole, string > { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); } } 新增 專案名稱 IdentityWebAPI 並選擇 API 將DAL 專案加入參考 安裝所需套件 install-package AutoMapper install-package IdentityServer4 instal...

Material Admin

ng new website --style=scss --routing --skip-tests Install Material Component npm install --save @angular/material @angular/cdk npm install --save hammerjs npm install @angular/flex-layout modify main.ts import 'hammerjs'; modify style.scss @import '~@angular/material/prebuilt-themes/indigo-pink.css'; in app below ng g module shared shared.module.ts ---------------- import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FlexLayoutModule } from '@angular/flex-layout'; import { MatAutocompleteModule, MatButtonModule, MatButtonToggleModule, MatCardModule, MatCheckboxModule, MatChipsModule, MatDatepickerModule, MatDialogModule, MatExpansionModule, MatGridListModule, MatIconModule, MatInputModule, MatListModule, MatMenuModule, MatNativeDateModule, MatPaginatorModule, MatProgressBarModule, MatProgressSpinn...

Asp.net Core 2 Identity WebApi

圖片
Let’s create new webapi ASP.NET Core project.  Create folder UserAuthentication , and inside that folder run command dotnet new webapi . Add Swagger You can test now your app using Postman. Method: POST, url: “/api/account/register” And this is a response Status is 200 Ok. If your register form isn’t valid you will get response status 400 Bad Request and message with your errors. Now when you are registered, you can login. For that you need only your email and password. Method: POST, url: “/api/account/login” And the response is our JWT. In our controller there is one method called GetSecuredData() for testing our tokens. You can get that data only if you are logged in. Let’s try that in Postman. After you log in, copy token that you get from server and paste it in header of request. Key is Authorization and Value is “Bearer (your token here)” with one space between word Bearer and your token. Like this Don’t forget to set method GET and change u...

From Zero

Asp.net Core 2.0 空白專案 Add appsettings.json { "ConnectionStrings": {     "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=MyDb;Trusted_Connection=True;MultipleActiveResultSets=true"   } } Cerate Model Folder Add ApplicationUser.cs    public class ApplicationUser :IdentityUser     {         public ApplicationUser()        : base()         {         }         public ApplicationUser(string userName, string firstName, string lastName, DateTime birthDay)             : base(userName)         {             base.Email = userName;             this.FirstName = firstName;             this.LastName = lastName;             this.BirthDay = birthD...