mvc登录授权特性
2024-08-25 19:47:57
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
{}
最新文章
- plist文件、NSUserDefault 对文件进行存储的类、json格式解析
- C#如何在钉钉开发平台中创建部门
- Linux IO模型和网络编程模型
- VS中两个常用辅助工具
- 数据库表 copy
- 解密电子书之三:MCU(君正)
- Hibernate遇到oracle之主键生成策略
- JavaScript-Curry
- python科学计算之numpy
- javascript中函数的执行环境、作用域链、变量对象与活动对象
- apollo1.7.1初探(二)使用apollo订阅主题,发布主题消息
- Json序列化自定义属性名称
- 增删改查Spring+MyBatis
- Android下WPS打开Excel2007版也有问题
- url提交参数类
- 转:在centos7上安装memcache
- python中各种数据类型
- Using Fetch to rewrite JSON
- 基于二进制RPC协议法的轻量级远程调用框架 ---- Hessian
- 铁乐学python_day01-和python有关的唠嗑
热门文章
- xth的第 12 枚硬币(codevs 1366)
- 利用C语言中的函数指针实现c++中的虚函数
- MySQL Master High Available 理论篇(一)
- [转]C#操作SQL Server数据库
- pthread_rwlock pthread读写锁
- gradle配置国内的镜像
- [Cypress] Test Variations of a Feature in Cypress with a data-driven Test
- hdu1285 拓扑排序+优先队列
- 【BASH】bash shell的使用实例
- thymeleaf+springboot找不到html,只返回了字符串