随笔分类 -  C#

摘要:因需要在用户列表中点详情按钮来到当前页,所以需要展示分组详情,并展示当前所属角色组的用户 public async Task<ActionResult> Details(string id) { //查找是否存在角色组 var role = await _roleManager.FindByIdAs 阅读全文
posted @ 2020-06-30 14:04 liessay 阅读(980) 评论(0) 推荐(0)
摘要:角色删除方法 [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Delete(string id) { var role = await _roleManager.FindByIdAsync(id); if ( 阅读全文
posted @ 2020-06-30 10:19 liessay 阅读(667) 评论(0) 推荐(0)
摘要:因只有角色名能修改故继续使用创建角色的视图模型 using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace Shop.ViewModel { public class CreateEditRo 阅读全文
posted @ 2020-06-30 10:05 liessay 阅读(494) 评论(0) 推荐(0)
摘要:首先创建视图模型 using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace Shop.ViewModel { public class CreateEditRoleViewModel { [ 阅读全文
posted @ 2020-06-30 10:02 liessay 阅读(527) 评论(0) 推荐(0)
摘要:需要将目前所有角色名显示出来,方法同用户管理 一、创建Index acction public async Task<ActionResult> Index() { var roles = await _roleManager.Roles.ToListAsync(); return View(rol 阅读全文
posted @ 2020-06-30 09:47 liessay 阅读(588) 评论(0) 推荐(0)
摘要:因角色管理需要有用户才能进行(需要将用户从角色中添加,删除)故角色管理代码依托用户管理 只需在Startup服务中添加角色管理即可完成 public void ConfigureServices(IServiceCollection services) { services.AddControlle 阅读全文
posted @ 2020-06-30 09:22 liessay 阅读(671) 评论(0) 推荐(0)
摘要:在实际使用时会发现很多字段在IdentityUser中并不存在,比如增加生日,地址等字段,可在模型类中实现自己的模型并继承自IdentityUser,需要修改的代码为以下类 一、新增模型 using System; using Microsoft.AspNetCore.Identity; names 阅读全文
posted @ 2020-06-29 17:07 liessay 阅读(1140) 评论(0) 推荐(1)
摘要:目前用户管理的增删改查及登录功能已经全部实现,但存在一个问题,登录后要取消登录按钮显示退出按钮,未登录应该有注册按钮,现实现过程如下 一、Startup.cs中增加服务 app.UseAuthentication(); 二、修改用户管理主页 注入服务 @inject SignInManager<Id 阅读全文
posted @ 2020-06-29 16:05 liessay 阅读(877) 评论(0) 推荐(0)
摘要:一、建立LoginViewModel视图模型 using System.ComponentModel.DataAnnotations; namespace Shop.ViewModel { public class LoginViewModel { [Required] [Display(Name 阅读全文
posted @ 2020-06-29 15:11 liessay 阅读(976) 评论(0) 推荐(0)
摘要:修改用户不能修改Id及用户名所以创建视图模型时需要去除,新增用户跟修改用户基本视图一直,所以不再做演示 一、新建UpdateUserViewModel视图模型 using System.ComponentModel; using System.ComponentModel.DataAnnotatio 阅读全文
posted @ 2020-06-29 14:09 liessay 阅读(896) 评论(0) 推荐(1)
摘要:用户注册主要有2个方法,1、密码加密 2、用户注册 3、ASP.NET Core Identity 使用密码策略、锁定和 cookie 配置等设置的默认值。 可以在类中重写这些设置 Startup(官方详情点这里) 首先创建CreateUserViewModel视图模型 using System.C 阅读全文
posted @ 2020-06-29 13:45 liessay 阅读(927) 评论(0) 推荐(0)
摘要:在Controllers中新建AccountController,并在构造方法(函数)中注入SignInManager,UserManager UserManager 用户管理(注册,查找,修改,删除用户等) SignInManager 用户登录管理(登录,注销等) private readonly 阅读全文
posted @ 2020-06-29 13:36 liessay 阅读(1177) 评论(0) 推荐(0)
摘要:理论知识微软官方文档最完整,最详细,这里只一步步的介绍如何使用,地址:https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/?view=aspnetcore-3.1 一、新建Mvc项目 二、加入EF依赖 浏览输入en 阅读全文
posted @ 2020-06-29 13:10 liessay 阅读(1150) 评论(1) 推荐(1)
摘要:系统默认提供了获取当前用户的api方法 https://localhost:44364/api/identity/my-profile 手工实现方法:abp后台获取当前用户需要在AppService应用层注入CurrentUser currentUser,如本例 using System; usin 阅读全文
posted @ 2020-06-23 13:18 liessay 阅读(3451) 评论(0) 推荐(0)
摘要:因为Abp vNext没找到Vue的模板,网上也没找到相关vNext的例子,只能自己试着写写,asp.net core abp vue都是刚学不久,所以很粗糙也可能有错误的地方,如果您看到请指正,谢谢 一、新建Vue项目,为了方便我是用vue ui方式建的,增加了element(样式),axios( 阅读全文
posted @ 2020-06-23 12:56 liessay 阅读(3598) 评论(1) 推荐(1)
摘要:在Shop.Application.Contracts项目中Permissions目录下ShopPermissions定义权限名 namespace Shop.Permissions { public static class ShopPermissions { public const strin 阅读全文
posted @ 2020-06-21 17:27 liessay 阅读(1478) 评论(0) 推荐(0)
摘要:App.vue添加组件 <template> <div id="app"> <dataTable></dataTable> </div> </template> <script> import dataTable from "./components/dataTable.vue"; export d 阅读全文
posted @ 2020-06-19 15:59 liessay 阅读(353) 评论(0) 推荐(0)
摘要:在swagger中查看登录需要用post方式访问,Abp需要用application/json方式调用 请求体 Postman调用方式 例:访问所有用户,调用Api地址为http://localhost:21021/api/services/app/User/GetAll,访问方式为Get Head 阅读全文
posted @ 2020-06-13 17:07 liessay 阅读(987) 评论(0) 推荐(0)
摘要:有时候实际业务中主键不一定叫Id,比如示例数据库Northwind中的RegionID,TerritoryID等,本示例用Abp框架并以Northwind数据库Region表为数据依据 一、在Core领域层创建Region实体 using System.ComponentModel.DataAnno 阅读全文
posted @ 2020-06-13 15:48 liessay 阅读(584) 评论(0) 推荐(0)
摘要:此处演示为MVC项目,同样权限定义需要到Application中才能在获取API时进行权限验证 一、打开Sample.Core\Authorization\PermissionNames.cs增加授权名称 代码 //Controller权限名称 public const string Pages_A 阅读全文
posted @ 2020-06-13 09:07 liessay 阅读(675) 评论(0) 推荐(0)