You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

EFCORE+IDENTITYUSER实现快速用户登陆开发
一、源码描述
EFCore+IdentityUser实现快速用户登陆开发
环境VS2022 sql2019 .netcore2.1
二、功能介绍
运行前
1、可删除项目目录下的Migrations文件夹再进行数据库初始化迁移重新生成数据建库。
在VS2022中的PowerShell窗口
dotnet ef database update 
dotnet ef migrations add InitialCreate
在VS2022Package Manager Console窗口
Add-Migration InitialCreate
Update-Database
2、重新生成数据库后运行项目由于没有配置Swagger需要Postman访问接口。
浏览器访问以下地址即可创建管理员http://localhost:5000/api/Account/AddAdmin。
管理员的用户名密码可在Controllers目录下的AccountController.cs的public async Task<string> AddAdmin()方法中修改。
该语句设置密码var result = await _userManager.CreateAsync(user, "51Aspx*");
该语句检查是否设置成功var resultSignIn = await _signInManager.PasswordSignInAsync(user.UserName, "51Aspx*", true, false);
3、登录验证在Postman用post请求接口
接口地址http://localhost:5000/api/Account/Login
接口数据格式:
{
    "Username":"admin",
    "Password":"51Aspx*",
    "RememberMe":true
}
用户名与密码在步骤2中设置。
其他设置请参看Models文件夹、Startup.cs等文件。
掌握以后开发效率会飞起来。
三、注意事项
1、在项目web.config修改数据库连接字符串附加数据库。
2、管理员账号与密码admin 51aspx 。
3、ctrl+F5运行即可。
作者: coderbest
如需获得该源码的视频、更新等更多资料请访问: https://www.51aspx.com/Code/TheUserLogsIn
------------------------------------------------------------------------------------------------
源码服务专家
官网: https://www.51aspx.com
讨论圈: https://club.51aspx.com/
平台声明:
1.51Aspx平台上提供下载的资源为免费、共享、商业三类源码,其中免费和共享源码仅供个人学习和研究使用,商业源码请在相应的授权许可条件下使用;
2.51Aspx平台对提供下载的软件及其它资源不拥有任何权利,其版权归属源码合法拥有者所有;
3.著作权人发现本网站载有侵害其合法权益的内容或作品,请与我们联系( 登录官网与客服反馈或发送邮件到support@51Aspx.com
4.51Aspx平台不保证提供的下载资源的准确性、安全性和完整性;
友情提示:
一般数据库文件默认在 DB_51Aspx 文件夹下
默认账号密码一般均为51Aspx
关于源码使用常见问题及解决方案,请参阅: https://www.51aspx.com/Help