Aop检查Session,全局过滤器和No全局过滤器
全局过滤器:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace UpdateService.Filter
- {
- public class AccessControl : ActionFilterAttribute
- {
- public override void OnActionExecuting(ActionExecutingContext filterContext)
- {
- bool flag = false;
- List<FilterAttribute> list = filterContext.ActionDescriptor.GetFilterAttributes(false).ToList();
- list.AddRange(filterContext.ActionDescriptor.ControllerDescriptor.GetFilterAttributes(false).ToList());
- foreach (var item in list)
- {
- bool b = item.Match(new AccessControlNoFilter());
- if (b == true)
- {
- flag = true;
- break;
- }
- }
- if (flag == true)
- {
- base.OnActionExecuting(filterContext);
- }
- else
- {
- HttpContextBase context = filterContext.HttpContext;
- HttpResponseBase response = filterContext.HttpContext.Response;
- HttpRequestBase request = filterContext.HttpContext.Request;
- if (context.Session["User"] == null)
- {
- if (request.IsAjaxRequest())
- {
- HttpUnauthorizedResult httpStatus = new HttpUnauthorizedResult("Session Timeout");
- filterContext.Result = httpStatus;
- //禁用web.config中的form认证
- //<!--<authentication mode="Forms">
- //<forms loginUrl="~/Account/Login" timeout="2880" />
- //</authentication>-->
- }
- else
- {
- ContentResult con = new ContentResult();
- con.Content = "<script>alert('当前会话已超时!');location='/Home/Login';</script>";
- filterContext.Result = con;
- }
- }
- base.OnActionExecuting(filterContext);
- }
- }
- }
- }
NO全局过滤器:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace UpdateService.Filter
- {
- public class AccessControlNoFilter : ActionFilterAttribute
- {
- public override void OnActionExecuting(ActionExecutingContext filterContext)
- {
- base.OnActionExecuting(filterContext);
- }
- }
- }
FilterConfig.cs
- public class FilterConfig
- {
- public static void RegisterGlobalFilters(GlobalFilterCollection filters)
- {
- //全局Session检查
- filters.Add(new AccessControl());
- }
- }
Jquery:
- $(function () {
- // 设置jQuery Ajax全局的参数
- $.ajaxSetup({
- complete: function (jqXHR, textStatus, errorThrown) {
- if (jqXHR.statusText == "Session Timeout") {
- alert('当前会话已超时!');
- location = "/Home/Login";
- }
- }
- });
- });
Aop检查Session,全局过滤器和No全局过滤器的更多相关文章
- asp.net core MVC 全局过滤器之ExceptionFilter异常过滤器(一)
本系类将会讲解asp.net core MVC中的内置全局过滤器的使用,将分为以下章节 asp.net core MVC 过滤器之ExceptionFilter异常过滤器(一) asp.net cor ...
- JNI/NDK开发指南(十)——JNI局部引用、全局引用和弱全局引用
转自:http://blog.csdn.net/xyang81/article/details/44657385 这篇文章比较偏理论,详细介绍了在编写本地代码时三种引用的使用场景和注意事项.可能看 ...
- NDK开发之引用(局部引用,全局引用,虚全局引用)
1.先引出我遇到的一个问题(我觉得先写问题,这样印象更深刻一点): Android Java层在调用本地jni代码的时候, 会维护一个局部引用表(最大长度是512), 一般jni函数调用结束后, jv ...
- ThinkPHP中:检查Session是否过期
1.创建Session public function index(){ $sess_time=time(); session('name','andy'); session('time_stamp' ...
- rstful登陆认证并检查session是否过期
一:restful用户视图 #!/usr/bin/env python # -*- coding:UTF-8 -*- # Author:Leslie-x from users import model ...
- Taurus.MVC WebAPI 入门开发教程6:全局控制器DefaultController与全局事件。
系列目录 1.Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行. 2.Taurus.MVC WebAPI 入门开发教程2:添加控制器输出Hello World. 3.Tau ...
- 实现MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器
MVC开发中几种以AOP方式实现的Filters是非常好用的,默认情况下,我们通过App_Start中的FilterConfig来实现的过滤器注册是全局的,也就是整个应用程序都会使用的,针对单独的Fi ...
- MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器
实现MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器 MVC开发中几种以AOP方式实现的Filters是非常好用的,默认情况下,我们通过A ...
- MVC过滤器:自定义授权过滤器
一.授权过滤器 授权过滤器用于实现IAuthorizationFilter接口和做出关于是否执行操作方法(如执行身份验证或验证请求的属性)的安全策略.AuthorizeAttribute类继承了IAu ...
随机推荐
- 说说iDempiere = OSGi + ADempiere的OSGi
怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ 我对iDempiere还完全摸不着头脑,正好在学习之际,应erp100的@纵横四海 邀请 ...
- docker build 的 cache 机制
cache 机制注意事项 可以说,cache 机制很大程度上做到了镜像的复用,降低存储空间的同时,还大大缩短了构建时间.然而,不得不说的是,想要用好 cache 机制,那就必须了解利用 cache 机 ...
- LaTeX数学公式输入
[置顶 Tips ] 在 WinEdt 中快速添加公式字符而不必手动打出一个个letters~: 即会出现如下 GUI Page Control : ------------------------- ...
- jquery 设置checkbox选中 和获取选中值
经常用到经常网上搜,这次写下来. 1,设置选中: $('#nrowid').prop('checked', false); 2,取选中项的值: $('#nrowid').prop("chec ...
- base、this、new、override、abstract、virtual、static
前言 本文主要来讲解一下C#中,自己觉得掌握的不怎么样或者用的不多,不太熟悉的关键字,主要包括base.this.new.override.abstract.virtual以及针对static字段和s ...
- OSI7层网络模型
物理层在OSI参考模型中,物理层(Physical Layer)是参考模型的最低层,也是OSI模型的第一层.物理层的主要功能是:利用传输介质为数据链路层提供物理连接,实现比特流的透明传输.物理层的作用 ...
- 微信模板消息php
微信的模板消息需要认证的公众号后台申请 申请通过后就可以用平台定义的消息模板了 define('IN_ECS', true); require(dirname(__FILE__) . '/includ ...
- 设置phpcms v9黄页模块作为首页方法
如果我们根据需要,想把黄页作为单独的网站,我们可以用模块化安装,并且首页设置,那么仿站网就说说详细的步骤.首先,我们需要安装最新版本的phpcms V9其次,下载黄页模块,然后进行根目录的替换.再次, ...
- The Way to Go读书笔记_第4章_基本结构和基本数据类型
“_”标识符 _ 本身就是一个特殊的标识符,被称为空白标识符.它可以像其他标识符那样用于变量的声明或赋值(任何类型都可以赋值给它),但任何赋给这个标识符的值都将被抛弃,因此这些值不能在后续的代码中使用 ...
- std::thread “terminate called without an active exception”
最近在使用std::thread的时候,遇到这样一个问题: std::thread t(func); 如果不使用调用t.join()就会遇到 "terminate called whitho ...