当前位置:网站首页>ASP. NET CORE Study11
ASP. NET CORE Study11
2022-06-28 12:35:00 【When the human stars shine】
Simple personal blog project construction notes
1. summary
Project outline
By making a simple , Easy to understand personal blog project , It is very simple to add, delete, modify and check , To learn better asp.net core, This project uses asp.net core webapi+elementui To do it .
2. Database design
Article table
ID
Article title
Article content
Creation time
Type of article ID
Browse volume
Like
author ID
Article type table
ID
Type name
Author's list
ID
full name
account number
password MD5
3. Architecture design
Storage layer
Service layer
MD5 encryption
public static string MD5Encrypt32(string password)
{
string pwd = "";
MD5 md5 = MD5.Create(); // Instantiate a md5 Antithetic image
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
for (int i = 0; i < s.Length; i++)
{
pwd = pwd + s[i].ToString("X");
}
return pwd;
}
JWT Use
JWT to grant authorization
1. Add one webapi project
2. install Nuget Package System.IdentityModel.Tokens.Jwt
var claims = new Claim[]
{
new Claim(ClaimTypes.Name, " Zhang San ")
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("SDMC-CJAS1-SAD-DFSFA-SADHJVF-VF"));
//issuer On behalf of Token Of Web Applications ,audience yes Token Accepted by
var token = new JwtSecurityToken(
issuer: "http://localhost:6060",
audience: "http://localhost:5000",
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddHours(1),
signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256)
);
var jwtToken = new JwtSecurityTokenHandler().WriteToken(token);
return jwtToken;
JWT authentication
install Microsoft.AspNetCore.Authentication.JwtBearer
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("SDMC-CJAS1-SAD-DFSFA-SADHJVF-VF")),
ValidateIssuer = true,
ValidIssuer = "http://localhost:6060",
ValidateAudience = true,
ValidAudience = "http://localhost:5000",
ValidateLifetime = true,
ClockSkew = TimeSpan.FromMinutes(60)
};
});
JWT Authorized authentication use
Swagger If you want to use authentication, you need to register the service, add the following code
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In=ParameterLocation.Header,
Type=SecuritySchemeType.ApiKey,
Description= " Type... Directly in the box below Bearer {token}( Notice that there is a space between the two )",
Name="Authorization",
BearerFormat="JWT",
Scheme="Bearer"
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference=new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[] {
}
}
});
AutoMapper
install Nuget AutoMapper.Extensions.Microsoft.DependencyInjection
Define a class , Inherit Profile
public class CustomAutoMapperProfile:Profile
{
public CustomAutoMapperProfile()
{
base.CreateMap<StudentEntity, StudentDto>();
}
}
Register in the service
services.AddAutoMapper(typeof(CustomAutoMapperProfile));
Constructor injection
private readonly IMapper _mapper;
public StudentsController(IMapper mapper)
{
this._mapper = mapper;
}
Complex mapping
base.CreateMap<Admin, AdminDto>()
.ForMember(dest => dest.RoleMsg, sourse => sourse.MapFrom(src => src.RoleInfo.RoleMsg));
User:
UserPwd -> Cannot return to the front end
UserName -> Back to front end
UserDTO:
UserName
边栏推荐
- Jerry's wif interferes with Bluetooth [chapter]
- KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
- [unity Editor Extension practice] find all prefabs referencing this picture
- Mr. Zhang responded to the first live broadcast with goods
- 关于IP定位查询接口的测评Ⅰ
- 2022年理财产品的常见模式有哪些?
- 我的NVIDIA开发者之旅-Jetson Nano 2gb教你怎么训练模型(完整的模型训练套路)
- Custom title bar view
- 杰理之wif 干扰蓝牙【篇】
- .NET混合开发解决方案24 WebView2对比CefSharp的超强优势
猜你喜欢

如何在Microsoft Exchange 2010中安装SSL证书

为什么CAD导出PDF没有颜色

Unity Editor Extension Foundation, GUI

《数字经济全景白皮书》消费金融数字化篇 重磅发布
思源官方付费同步使用指南
![[C language] use of nested secondary pointer of structure](/img/59/8b61805431e152995c250f6dd08e29.png)
[C language] use of nested secondary pointer of structure

ASP.NET CORE Study03

From simplekv to redis

MATLAB的官方网站上其实有很多MATLAB的学习和使用资料(文档、视频都有不少)

Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting
随机推荐
杰理之wif 干扰蓝牙【篇】
女子高考落榜读专科逆袭买千万别墅,考得不好真的没关系
cdc同步 如果数据库表的主键发生了变化,会同步成两个数据 还是会同步更新主键呢?
ASP. NET CORE Study03
请问通达信股票软件可靠吗?在上面交易股票安全吗?
Unity releases webgl and wakes up keyboard input on the mobile terminal inputfield
ASP.NET CORE Study01
思源官方付费同步使用指南
Ugui force refresh of layout components
Unity导入资源后还手动修改资源的属性?这段代码可以给你节约很多时间:AssetPostprocessor
双缓冲绘图
杰理之wif 干扰蓝牙【篇】
It really doesn't matter if a woman fails to pass the college entrance examination and buys thousands of villas in a counter attack
如何在Microsoft Exchange 2010中安装SSL证书
结构光之相移法+多频外差的数学原理推导
设置Canvas的 overrideSorting不生效
从SimpleKV到Redis
ASP.NET CORE Study02
KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
《数字经济全景白皮书》消费金融数字化篇 重磅发布