码迷,mamicode.com
首页 > Web开发 > 详细

Bootstrap+angularjs+MVC3+分页技术+角色权限验证系统

时间:2015-02-25 18:27:46      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

页面使用代码:

<script src="@Url.Content("~/Content/Bootstrap/js/bootstrap.min.js")"></script> < link href="@Url.Content("~/Content/Bootstrap/css/bootstrap.min.css")" rel="stylesheet" media="screen"/>

2.angularjs

<script src="@Url.Content("~/Scripts/angular.min.js")"></script>

 <script type="text/javascript">

    var app = angular.module("ControlState", []);     app.controller("Home/Login", function ($scope,$window) {         $scope.login = function(user) {              var url="@Url.Action("Login","Home")";                         $.post(url,user,function(ret){                    if(ret=="False"){                    art.dialog.tips(‘用户名或密码错误,请重新输入!‘, 1.5);                    $(‘form‘)[0].reset();                      $(‘form input‘)[0].focus();                                                                              }else{                        if(user.UserName=="admin")                            location="Index";                        else                            location="Contact";                    }            });          };               });

3.分页

技术分享
public ActionResult MessageBox(int?id){             int pageID=1;             if (id.HasValue) {                 pageID=id.Value;             }                           var list=DBFactory.GetEntities<Message>(MessageTable.MessageToUserID.Equal(SystemGlobalData.CURRENT_USERID).And(MessageTable.Deleted.Equal(0)));             var count=DBFactory.GetInt32Count(MessageTable.MessageToUserID.Equal(SystemGlobalData.CURRENT_USERID).And(MessageTable.Deleted.Equal(0)));             PagedList<Message> pList=new PagedList<Message>(list,pageID,5);             return View(pList );         }
技术分享

前端代码

技术分享View Code

 

4.权限角色验证

技术分享
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Xml.Linq;
using Moon.Orm; using mynorthdb;
namespace Razor.Moon {     /// <summary>     /// Description of CheckLoginAttribute.     /// </summary>     public class CustemerAuthenAttribute:AuthorizeAttribute     {         public new string[] ActionRoles { get; set; }         protected override bool AuthorizeCore(HttpContextBase httpContext)         {             if (httpContext == null) {                 throw new ArgumentNullException("HttpContext");             }             if (!httpContext.User.Identity.IsAuthenticated) {                 return false;             }             if (ActionRoles == null) {                 return true;             }             if (ActionRoles.Length == 0)             {                 return true;             }             if (ActionRoles.Contains(httpContext.User.Identity.Name))             {                 return true;             }             return false;         }         protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)         {             var  Request=filterContext.HttpContext.Request;             string url=Request.Url.Scheme+"://"+Request.Url.Authority+"/Home/Login";             filterContext.Result = new RedirectResult(url);         }         public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)         {             string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;             string actionName = filterContext.ActionDescriptor.ActionName;             string roles = ActionRoleManager.GetActionRoles(actionName, controllerName);             if (!string.IsNullOrWhiteSpace(roles)) {                 this.ActionRoles = roles.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);             }             base.OnAuthorization(filterContext);         }     } }
技术分享

 5.效果图

技术分享

6.项目下载

http://files.cnblogs.com/humble/%E9%A1%B9%E7%9B%AE%E5%8F%8A%E6%95%B0%E6%8D%AE%E5%BA%93.7z 

 

http://www.cnblogs.com/humble/p/3149734.html

Bootstrap+angularjs+MVC3+分页技术+角色权限验证系统

标签:

原文地址:http://www.cnblogs.com/chen110xi/p/4299894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!