添加项目文件。
This commit is contained in:
32
HT.Cloud.Code/Attribute/HandlerAdminAttribute.cs
Normal file
32
HT.Cloud.Code/Attribute/HandlerAdminAttribute.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace HT.Cloud.Code
|
||||
{
|
||||
/// <summary>
|
||||
/// 管理员特性,MVC使用
|
||||
/// </summary>
|
||||
public class HandlerAdminAttribute : ActionFilterAttribute
|
||||
{
|
||||
private readonly bool _isSuper;
|
||||
|
||||
public HandlerAdminAttribute(bool isSuper = true)
|
||||
{
|
||||
_isSuper = isSuper;
|
||||
}
|
||||
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
if (OperatorProvider.Provider.GetCurrent() != null && _isSuper == true ? OperatorProvider.Provider.GetCurrent().IsSuperAdmin : OperatorProvider.Provider.GetCurrent().IsAdmin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//filterContext.HttpContext.Response.WriteAsync("<script>top.location.href ='" + filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=403" + "';if(document.all) window.event.returnValue = false;</script>");
|
||||
filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=403");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user