public class CommonController : Controller
{ protected override void OnAuthorization(AuthorizationContext filterContext)
{
var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
var actionName = filterContext.ActionDescriptor.ActionName;
if (this.GetUserAuthorize(this.HttpContext.User.Identity.Name, controllerName, actionName))
{
base.OnAuthorization(filterContext);
}
else
{
const string ViewName = "~/Views/Account/Login.cshtml";
var vr = new ViewResult { ViewName = ViewName };
filterContext.Result = vr;
}
} private bool GetUserAuthorize(string userId,string controllerName,string actionName)
{
if (string.IsNullOrEmpty(userId))
{
return false;
} //访问数据库中相关的用户、角色、功能权限等表看是否具有访问此action的权限
//有返回true,否则false return true;
}

  

MVC授权的更多相关文章

  1. MVC授权认证

    处于安全性考虑,MVC可以完成授权认证,授权认证的方式如下: 1.配置Config文件,设置登录页面: <authentication mode="Forms"> &l ...

  2. MVC 授权过滤器 AuthorizeAttribute

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  3. ASP.NET Core MVC 授权的扩展:自定义 Authorize Attribute 和 IApplicationModelProvide

    一.概述 ASP.NET Core MVC 提供了基于角色( Role ).声明( Chaim ) 和策略 ( Policy ) 等的授权方式.在实际应用中,可能采用部门( Department , ...

  4. 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现

    本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...

  5. MVC授权不通过之后不执行任何自定义ActionFilter

    如下一个Action [Authorize] [F1]//自定义过滤器,继承自ActionFilter public ActionResult Index() { return View(); } 如 ...

  6. ASP.NET MVC 随想录—— 使用ASP.NET Identity实现基于声明的授权,高级篇

    在这篇文章中,我将继续ASP.NET Identity 之旅,这也是ASP.NET Identity 三部曲的最后一篇.在本文中,将为大家介绍ASP.NET Identity 的高级功能,它支持声明式 ...

  7. asp.net core系列 40 Web 应用MVC 介绍与详细示例

    一. MVC介绍 MVC架构模式有助于实现关注点分离.视图和控制器均依赖于模型. 但是,模型既不依赖于视图,也不依赖于控制器. 这是分离的一个关键优势. 这种分离允许模型独立于可视化展示进行构建和测试 ...

  8. ASP.NET Core MVC 概述

    https://docs.microsoft.com/zh-cn/aspnet/core/mvc/overview?view=aspnetcore-2.2 ASP.NET Core MVC 概述 20 ...

  9. 【ASP.NET Identity系列教程(一)】ASP.NET Identity入门

    注:本文是[ASP.NET Identity系列教程]的第一篇.本系列教程详细.完整.深入地介绍了微软的ASP.NET Identity技术,描述了如何运用ASP.NET Identity实现应用程序 ...

随机推荐

  1. AngularJs的UI组件ui-Bootstrap分享(十)——Model

    Model是用来创建模态窗口的,但是实际上,并没有Model指令,而只有$uibModal服务,创建模态窗口是使用$uibModal.open()方法. 创建模态窗口时,要有一个模态窗口的模板和对应的 ...

  2. java语言程序设计(一)-2

    (一)jdk安装及环境变量配置 1.jdk下载 下载地址http://www.oracle.com/technetwork/java/javase/downloads/index.html,下载SE标 ...

  3. NPOI 2.0 读取、编辑、保存Excel文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  4. JSON介绍

    JSONhttp://www.json.org/json-zh.html JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机 ...

  5. 数据类型int、bigint、smallint 和 tinyint范围

      bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字).存储大小为 8 个字节. int ...

  6. @property? @property?说说他身后的事情。

    @property 后面可以有哪些修饰符? 1.线程安全的       aaomic.nonatomic 2.访问权限的       readonly.readwrite 3.内存管理(ARC) as ...

  7. CreateFile函数详解

    CreateFile函数详解 CreateFile The CreateFile function creates or opens the following objects and returns ...

  8. php基础的一点注意事项

    1.要弄懂"~"运算符的计算方法,首先必须明白二进制数在内存中的存放形式,二进制数在内存中是以补码的形式存放的 另外正数和负数的补码不一样,正数的补码,反码都是其本身,即: 正数9 ...

  9. C#检测本地网络状态

    using System; using System.Runtime.InteropServices; public static class NetTool { [Flags] private en ...

  10. Android Studio项目目录结构介绍——android菜鸟成长之路

    在Android Studio中,提供了以下几种项目结构类型 我们一般常用的有以下两种结构: Project 结构类型 app/build/ app模块build编译输出的目录 app/build.g ...