public class CommonAuthorize : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return UserHelper.CurrentUser != null;
} public override void OnAuthorization(AuthorizationContext filterContext)
{
if (!filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) && !filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
{
if (UserHelper.CurrentUser == null)
{
filterContext.Result = new RedirectResult(string.Format("/OAuth2/IndexUserInfo?returnUrl={0}", filterContext.HttpContext.Request.RawUrl));
}
}
}
}

使用

[CommonAuthorize]
public class BaseController : Controller
{}

最新文章

  1. plist文件、NSUserDefault 对文件进行存储的类、json格式解析
  2. C#如何在钉钉开发平台中创建部门
  3. Linux IO模型和网络编程模型
  4. VS中两个常用辅助工具
  5. 数据库表 copy
  6. 解密电子书之三:MCU(君正)
  7. Hibernate遇到oracle之主键生成策略
  8. JavaScript-Curry
  9. python科学计算之numpy
  10. javascript中函数的执行环境、作用域链、变量对象与活动对象
  11. apollo1.7.1初探(二)使用apollo订阅主题,发布主题消息
  12. Json序列化自定义属性名称
  13. 增删改查Spring+MyBatis
  14. Android下WPS打开Excel2007版也有问题
  15. url提交参数类
  16. 转:在centos7上安装memcache
  17. python中各种数据类型
  18. Using Fetch to rewrite JSON
  19. 基于二进制RPC协议法的轻量级远程调用框架 ---- Hessian
  20. 铁乐学python_day01-和python有关的唠嗑

热门文章

  1. xth的第 12 枚硬币(codevs 1366)
  2. 利用C语言中的函数指针实现c++中的虚函数
  3. MySQL Master High Available 理论篇(一)
  4. [转]C#操作SQL Server数据库
  5. pthread_rwlock pthread读写锁
  6. gradle配置国内的镜像
  7. [Cypress] Test Variations of a Feature in Cypress with a data-driven Test
  8. hdu1285 拓扑排序+优先队列
  9. 【BASH】bash shell的使用实例
  10. thymeleaf+springboot找不到html,只返回了字符串