当前位置: 首页 > news >正文

江苏做网站的公司哪家做网站

江苏做网站的公司,哪家做网站,中文网站建设英文网站建设,手机端网站源码在使用 WebForm 技术开发网站的时候#xff0c;微软就提供了 Form 身份认证#xff0c;这使得登录认证简单了许多#xff0c;不同于 WebForm 以及后来的 Asp.Net Mvc#xff0c;Asp.Net Core 中的身份认证与之前相比使用更加便捷#xff0c;本文介绍 Asp.Net Core 2.0 多角… 在使用 WebForm 技术开发网站的时候微软就提供了 Form 身份认证这使得登录认证简单了许多不同于 WebForm 以及后来的 Asp.Net MvcAsp.Net Core 中的身份认证与之前相比使用更加便捷本文介绍 Asp.Net Core 2.0 多角色授权认证首先我们需要在 Startup.cs 中开启授权认证相关模块中间件代码如下 services.AddAuthentication(options{options.DefaultChallengeScheme CookieAuthenticationDefaults.AuthenticationScheme;options.DefaultAuthenticateScheme CookieAuthenticationDefaults.AuthenticationScheme;}) .AddCookie(options {options.LoginPath /Account/;options.Cookie.HttpOnly true;}); services.AddTransientHttpContextAccessor();app.UseAuthentication(); 之后我们在登录模块编写多角色登录逻辑代码如下 [HttpPost] public async TaskIActionResult Login(string userCode, string userPassword, int userType 0, string returnUrl ) {if ((userCode.Trim().ToLower() admin || userCode.Trim().ToLower() user) userPassword.Trim().ToLower() 123456){var claimsIdentity new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);claimsIdentity.AddClaim(new Claim(ClaimTypes.Sid, userCode));if (userType RoleTypeEnum.UserType_Admin){claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, RoleTypeEnum.Admin));}else{claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, RoleTypeEnum.User));}var claimsPrincipal new ClaimsPrincipal(claimsIdentity);await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties{ExpiresUtc DateTime.UtcNow.AddMinutes(20)});if (!string.IsNullOrEmpty(returnUrl)){return this.Redirect(returnUrl);}else{if (userType RoleTypeEnum.UserType_Admin){return this.Redirect(Url.Action(Index, Home, new { area Admin }));}else{return this.Redirect(Url.Action(Index, Home, new { area User }));}}}else{return this.Content(string.Format(scriptalert(用户名或者密码错误);location.href{0}/script, Url.Action(Index, Account)), text/html;charsetutf8);} } 本例只提供管理和普通用户两种角色类别可以根据情况自由添加接着我们就可以在相关授权模块添加 Authorize 元属性来进行角色授权代码如下 // 管理员模块 [Authorize(Roles RoleTypeEnum.Authorize_Admin)] [Area(Admin)] public class BaseController : Controller {protected string userCode;public BaseController(IHttpContextAccessor contextAccessor){this.userCode contextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value;}protected void InitCookieViewData(){ViewData.Add(UserCode, this.userCode);} } // 用户模块 [Authorize(Roles RoleTypeEnum.Authorize_User)] [Area(User)] public class BaseController : Controller {protected string userCode;public BaseController(IHttpContextAccessor contextAccessor){this.userCode contextAccessor.HttpContext.User.FindFirst(ClaimTypes.Sid).Value;}protected void InitCookieViewData(){ViewData.Add(UserCode, this.userCode);} } 到此多角色授权认证已经结束而且我们也获得了登录的角色信息退出登录的代码如下 public async TaskIActionResult Logout() {await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);return this.Redirect(Url.Action(Index, Account, new { area })); } 本文已提供案例下载地址。 原文地址https://www.liziwu.net/topic/31.html.NET社区新闻深度好文微信中搜索dotNET跨平台或扫描二维码关注
http://www.sadfv.cn/news/83357/

相关文章:

  • 常州制作网站公司乐清柳市阿里巴巴做网站的
  • 网站建设 ipv6珠海微信网站开发
  • 电子商务网站的重要性我的免费网是个什么网站
  • 中国旅游网站模板前端开发工程师需要考什么证
  • 恒丰建设集团有限公司 网站app推广的常用方法
  • 正规的营销型网站建设公司李志自己做网站
  • 网站建设沈阳做网站收入怎么样
  • 阿里云网站建设方案书一定要嘛怎么添加网站关键词
  • 做前端网站考虑兼容分辨率dw网站建设模板
  • 手机网站 pc网站模板内蒙网站建设
  • app 网站 同时做360度全景地图
  • 给了几张图让做网站学前端要多久
  • 网站备案时网站没有内容可以微信小程序开发平台官网登录
  • 贵州网站seo建筑企业资质
  • 国际域名网站邯郸网站制作哪家好
  • 营销网站建设的步骤wordpress建站视频
  • 普通网站 seo 多少钱电影站的seo
  • html5网站开发公司李沧做网站
  • 做阿里渠道的销售要有哪些网站网站备案的接入商
  • asp.net手机网站开发烟台html5网站建设
  • 天津市哪里有做网站的青海城乡和住房建设厅网站
  • 南宁网站建设怎样建立一个好网站博创安泰网站建设
  • 站长工具seo综合查询怎么提高网站排名
  • 网站前台右侧怎么做二维码银川网站设计联系电话
  • 无法进入建设银行网站网站后台 全局配置
  • 成都seo网站建设引流推广公司
  • 深圳网站运营慈溪网页设计
  • h5企业网站源码知名企业网站大全
  • 河北建设部官方网站网站建设单选题
  • 门户网站建设依据五屏网站建设多少钱