Bootstrap+angularjs+MVC3+分页技术+角色权限验证系统
1.Bootstrap使用教程
相关教程: http://www.bootcss.com/components.html
页面使用代码:
<link href="@Url.Content("~/Content/Bootstrap/css/bootstrap.min.css")" rel="stylesheet" media="screen"/>
2.angularjs
<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.分页
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.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.项目下载
https://files.cnblogs.com/humble/%E9%A1%B9%E7%9B%AE%E5%8F%8A%E6%95%B0%E6%8D%AE%E5%BA%93.7z
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
2012-06-22 Moon.ORM 4.0 发布