mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-21 02:57:54 +08:00
@@ -9,7 +9,11 @@
|
||||
// <copyright file="BaseController.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>基础控制器,设置权限</summary>
|
||||
// <summary>
|
||||
// 基础控制器
|
||||
// 继承该控制器可以防止未登录查看
|
||||
// 继承该控制器后,如果想访问控制器中存在,但模块配置里面没有的Action(如:Home/Git),请使用AnonymousAttribute
|
||||
// </summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using Infrastructure.Helper;
|
||||
@@ -35,26 +39,22 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return;
|
||||
}
|
||||
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
||||
var actionname = filterContext.ActionDescriptor.ActionName;
|
||||
var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name == actionname);
|
||||
if (function == null)
|
||||
throw new Exception("未能找到Action");
|
||||
|
||||
if (controllername != "home") //主页控制器无需权限控制
|
||||
var anonymous = function.GetCustomAttribute(typeof(AnonymousAttribute));
|
||||
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
||||
//当前登录用户没有Action记录&&Action没有anonymous标识
|
||||
if (module == null && anonymous == null)
|
||||
{
|
||||
var actionname = Request.RequestContext.RouteData.Values["action"].ToString();
|
||||
var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name == actionname);
|
||||
if (function == null)
|
||||
throw new Exception("未能找到Action");
|
||||
|
||||
var anonymous = function.GetCustomAttribute(typeof(AnonymousAttribute));
|
||||
|
||||
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
||||
if (module == null && anonymous == null)
|
||||
{
|
||||
filterContext.Result = new RedirectResult("/Login/Index");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewBag.Module = module; //为View显示服务,主要是为了显示按钮
|
||||
}
|
||||
filterContext.Result = new RedirectResult("/Login/Index");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewBag.Module = module; //为View显示服务,主要是为了显示按钮
|
||||
}
|
||||
|
||||
base.OnActionExecuting(filterContext);
|
||||
|
Reference in New Issue
Block a user