源码:MVC中基于表单的用户身份验证与角色授权

时间:2020-07-28 08:32:50
【文件属性】:
文件名称:源码:MVC中基于表单的用户身份验证与角色授权
文件大小:9.4MB
文件格式:7Z
更新时间:2020-07-28 08:32:50
MVC 1.示例代码完整可用,具备在MVC使用表单身份验证,角色授权功能。 并且支持cookie加密。 2.为了方便教学,整个项目末连接数据库,将用户名及角色名称写死了。使用时,自行调用数据库即可。 3.实际使用时将cookie角色写入部分放到Global.asax文件,可解决部分浏览器关闭后要重新登陆问题。如下所示: protected void Application_AuthenticateRequest(Object sender, EventArgs e) { if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated) { if (HttpContext.Current.User.Identity is FormsIdentity) { //Get current user identitied by forms FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity; // get FormsAuthenticationTicket object FormsAuthenticationTicket ticket = id.Ticket; string userData = ticket.UserData; string[] roles = userData.Split(','); // set the new identity for current user. HttpContext.Current.User = new GenericPrincipal(id, roles); } } } }

网友评论

  • 资源不可用,少了model
  • 源码是可用的,不过重点没说出来