Web/Controllers/Filter/AuthAttribute.cs
(完整代码) 2KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace Conris.Web.Controllers.Filter
{
public class AuthAttribute : ActionFilterAttribute
{
private readonly Conris.Services.UserInfoService userInfoService = new Services.UserInfoService();
/// <summary>
/// 角色名称
/// </summary>
public Conris.DBA.ViewModel.UserType Code { get; set; }
/// <summary>
/// 验证权限(action执行前会先执行这里)
/// </summary>
/// <param name="filterContext"></param>
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//如果存在身份信息
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
ContentResult Content = new ContentResult();
Content.Content = string.Format("<script type='text/javascript'>alert('请先登录!');window.location.href='{0}';</script>", FormsAuthentication.LoginUrl);
filterContext.Result = Content;
}
else if (userInfoService.GetModel(Conris.Services.UserInfoService.GetNowUserID()).IsDisable=="0")
{
ContentResult Content = new ContentResult();
Content.Content = string.Format("<script type='text/javascript'>alert('您的账号存在异常,请联系管理员!');window.location.href='{0}';</script>", FormsAuthentication.LoginUrl);
filterContext.Result = Content;
}
else if (Code.Equals(Conris.DBA.ViewModel.UserType.Manage))
{
if (Conris.Services.UserInfoService.GetNowUserType()!="2"&&Conris.Services.UserInfoService.GetNowUserType()!="3")
{
ContentResult Content = new ContentResult();
Content.Content = "<script type='text/javascript'>alert('权限验证不通过!');history.go(-1);</script>";
filterContext.Result = Content;
}
}
else if (Code.Equals(Conris.DBA.ViewModel.UserType.Admin))
{
if (Conris.Services.UserInfoService.GetNowUserType() != "3")
{
ContentResult Content = new ContentResult();
Content.Content = "<script type='text/javascript'>alert('权限验证不通过!');history.go(-1);</script>";
filterContext.Result = Content;
}
}
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
