当前位置: 首页 > 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://wiki.neutronadmin.com/news/83357/

相关文章:

  • 西安做网站朋朋wordpress次级目录ftp
  • 网站建设与技术团队网站免费源码大全无需下载
  • 好商网的网站可以做中英文切换吗自媒体写作平台
  • 怎样才能建设只是于自己的网站辽宁建设工程信息网专家入库
  • 高端网站设计官网百度软件市场
  • 做lol数据的网站北京网站建设公司华网制作作
  • 网站开发找聚脑网最快网站备案
  • 太原h5建站东昌府做网站
  • 建设咖啡厅网站的意义平顶山营销型网站建设
  • 长沙网站的优化沧州网站制作网站
  • 业网站制作网站建设设计猫和老鼠
  • 做网站的去哪找客户网上网站怎么做
  • 老薛主机做两个网站做个电商平台要多少钱
  • 做外贸的j交易网站东莞企业网站建设
  • 网站备案费用多少公司百度网站建设
  • 做网站感觉挣不到钱啊wordpress获取权限
  • 云南哪几个建网站公司阿里巴巴国际站介绍
  • 关于设计方面的网站wordpress 多人编辑
  • 电影网站做流量关于推动门户网站建设d
  • 增城新塘网站建设用自己的电脑做网站需要备案吗
  • 南通网站建设要多少钱专业做推广的公司
  • 华强北网站建设网络推广代理
  • 北京网站优化培训淘宝美工做兼职的网站
  • stm32做网站服务器网页设计与网站建设报告
  • 青岛工程建设监理公司网站网站建设与管理需要什么软件有哪些
  • 济南做公司网站需要多少钱公司网站建设费如何入账
  • 安顺住房和城乡建设部网站辽宁公司网站建设
  • ipv6网站建设东莞移动版wordpress主题
  • php商城网站建设多少钱游戏网站免费入口
  • 免费照片的网站模板wordpress上传附件