View页面根据权限显示不同的内容
1、View中根据权限显示相关操作按钮
@if (CoreTools.CheckAction(HttpContext.Current, "Delete"))
{
<div class="pull-right margin-right-10">
<a id="delete" href="javascript:;" class="btn btn-fit-height red-haze">
<i class="fa fa-trash"></i> 删除
</a>
</div>
}
2、权限检查函数
public static bool CheckAction(string UserAccount, string ControllerName, string ActionName, bool SessionCache = true)
{
return GetRoleAction(UserAccount, SessionCache).Where(x => x.ControllerName == ControllerName && x.ActionName == ActionName).Count() > 0 ? true : false;
}
public static bool CheckAction(HttpContext context, string ActionName, bool SessionCache = true)
{
if (context.User.Identity.IsAuthenticated)
{
string UserAccount = context.User.Identity.Name;
string ControllerName = context.Request.RequestContext.RouteData.Values["controller"].ToString();
return CheckAction(UserAccount, ControllerName, ActionName, SessionCache);
}
else
{
return false;
}
}
3、根据权限显示相关菜单项
@foreach (var Menu in CoreTools.GetAllMenu().Where(x => x.RootLevel == 0).OrderBy(x=>x.OrderIndex))
{
//判断是否有子菜单
var SubMenus = CoreTools.GetRoleMenu(HttpContext.Current).Where(x => x.ParentGUID == Menu.GUID && x.RootLevel == 1).OrderBy(x => x.OrderIndex);
<li>
@if (SubMenus.Count() > 0)
{
<a href="javascript:;">
<i class="@Menu.IconClass"></i>
<span class="title">@Menu.DisplayName</span>
<span class="arrow "></span>
</a>
<ul class="sub-menu">
@foreach (var SubMenu in SubMenus)
{
<li>
<a href="@SubMenu.RequestUrl" id="@SubMenu.GUID">
<i class="fa @SubMenu.IconClass"></i>
@SubMenu.DisplayName
</a>
</li>
}
</ul>
}
</li>
}
View页面根据权限显示不同的内容的更多相关文章
- asp.net core根据用户权限控制页面元素的显示
asp.net core根据用户权限控制页面元素的显示 Intro 在 web 应用中我们经常需要根据用户的不同允许用户访问不同的资源,显示不同的内容,之前做了一个 AccessControlHelp ...
- MVC下 把数据库中的byte[]值保存成图片,并显示在view页面
MVC下 把数据库中的byte[]值转成图片,并显示在view页面 controller中的action方法 //显示图片[AllowAnonymous]public ActionResult Sho ...
- 如何让同一个字段在不同的view中显示不同的内容
many2one 字段默认显示 对象的name字段, 但也可以定义name_get方法显示不同的内容 如res.partner 对象可以根据 context 内容是否显示 客户的地址,职位,email ...
- Asp.Net Core 2.0 项目实战(11) 基于OnActionExecuting全局过滤器,页面操作权限过滤控制到按钮级
1.权限管理 权限管理的基本定义:百度百科. 基于<Asp.Net Core 2.0 项目实战(10) 基于cookie登录授权认证并实现前台会员.后台管理员同时登录>我们做过了登录认证, ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(1)-13基于OnActionExecuting全局过滤器,页面操作权限过滤控制到按钮级
1.权限管理 权限管理的基本定义:百度百科. 基于<Asp.Net Core 2.0 项目实战(10) 基于cookie登录授权认证并实现前台会员.后台管理员同时登录>我们做过了登录认证, ...
- [ASP.NET MVC] 使用CLK.AspNet.Identity提供依权限显示选单项目的功能
[ASP.NET MVC] 使用CLK.AspNet.Identity提供依权限显示选单项目的功能 CLK.AspNet.Identity CLK.AspNet.Identity是一个基于ASP.NE ...
- JS随鼠标坐标移动,显示浮动层内容
在表单等项目中往往会遇到类似于“备注”.“说明”等100个字内的内容需要显示. 这些内容如果全部呈现开,会影响布局和美观,确又没有必要设计一个层或是一个页面. 那么,我们可以把这些内容放到浮动层中,鼠 ...
- iframe中子页面通过js计算高度(使得页面不会显示不全)
使用过iframe的人,都知道,它是一个模版,里面有一个iframe,而iframe当中,是可以嵌套多个页面的.(比较常见的问题,就是iframe页面中,经常会出现内容显示不全的时候). 谨记,通过j ...
- ASP.NET MVC 学习3、Controller左手从Model获取数据,右手传递到View页面
参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/accessing-your-models-dat ...
随机推荐
- Linux进程栈和线程栈
参考资料: http://blog.csdn.net/xhhjin/article/details/7579145 总结: 1.进程的栈大小是在进程执行的时刻才能指定的,即不是在编译的时候决定 ...
- 二分图匹配 分类: ACM TYPE 2014-10-01 19:57 94人阅读 评论(0) 收藏
#include<cstdio> #include<cstring> using namespace std; bool map[505][505]; int n, k; bo ...
- Swift-5-流程控制
// Playground - noun: a place where people can play import UIKit // For-In 循环 // 1 遍历数字区间 ... { prin ...
- Swift-1-基本概念
// Playground - noun: a place where people can play // 通过代码快速了解swift常用知识,需要一定object-c基础 import UIKit ...
- 在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static
在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static ! 在C语言中,我们使用pthread_create ...
- AssetBundle机制相关资料收集
原地址:http://www.cnblogs.com/realtimepixels/p/3652075.html AssetBundle机制相关资料收集 最近网友通过网站搜索Unity3D在手机及其他 ...
- Cortex-M3/4的Hard Fault调试方法
1 Cortex-M3/4的Fault简介 Cortex-M3/4的Fault异常是由于非法的存储器访问(比如访问0地址.写只读存储位置等)和非法的程序行为(比如除以0等)等造成的.常见的4种异常及产 ...
- 7 天玩转 ASP.NET MVC — 第 7 天
目录 第 1 天 第 2 天 第 3 天 第 4 天 第 5 天 第 6 天 第 7 天 0. 前言 今天是开心的一天.因为我们终于来到了系列学习的最后一节.我相信你喜欢之前的课程,并从中学到了许多. ...
- linux使用crontab实现PHP执行定时任务及codeiginter参数传递相关
http://www.phpddt.com/php/linux-crontab.html crontab: yum install crontabs //安装 说明: /sbin/service cr ...
- ios下最简单的正则,RegexKitLite
ios下最简单的正则,RegexKitLite 1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中.备用地址:http://www.coco ...