IHttpModule接口事件执行 获取Session 找了很多国内的都不对,从国外转过来一个测试可用的
我的环境,asp.net4.0框架集
不多说上代码
public class MyHttpModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.PostAcquireRequestState += new EventHandler(Application_PostAcquireRequestState);
application.PostMapRequestHandler += new EventHandler(Application_PostMapRequestHandler);
} void Application_PostMapRequestHandler(object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
//这个判断不知道干什么,注释没事,
if (app.Context.Handler is IReadOnlySessionState || app.Context.Handler is IRequiresSessionState) {
// no need to replace the current handler
return;
} // swap the current handler 这一样不知道为什么必须声明,反正就是注释会报错,不信你试试看
app.Context.Handler = new MyHttpHandler(app.Context.Handler);
} void Application_PostAcquireRequestState(object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
//经过测试session从这里开始可以用了,我估计在下面的 MyHttpHander 里面应该也可以用,不过我没继续测试,有一些注意,这行代码下面本方法体里代码可以删掉,
MyHttpHandler resourceHttpHandler = HttpContext.Current.Handler as MyHttpHandler; if (resourceHttpHandler != null) {
// set the original handler back
HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler;
} // -> at this point session state should be available Debug.Assert(app.Session != null, "it did not work :(");
} public void Dispose()
{ } // a temp handler used to force the SessionStateModule to load session state
public class MyHttpHandler : IHttpHandler, IRequiresSessionState
{
//这个类竟然必须存在,不明所以,只知道可以用
internal readonly IHttpHandler OriginalHandler; public MyHttpHandler(IHttpHandler originalHandler)
{
OriginalHandler = originalHandler;
} public void ProcessRequest(HttpContext context)
{
// do not worry, ProcessRequest() will not be called, but let's be safe
throw new InvalidOperationException("MyHttpHandler cannot process requests.");
} public bool IsReusable
{
// IsReusable must be set to false since class has a member!
get { return false; }
}
}
}
IHttpModule接口事件执行 获取Session 找了很多国内的都不对,从国外转过来一个测试可用的的更多相关文章
- 了解IHttpModule接口事件执行顺便 获取Session
本文转载自:http://www.cnblogs.com/eflylab/archive/2008/05/29/1209767.html 最近公司一个项目让人SQL注入了-为了临时先解决这个问题,使攻 ...
- SQLServer中使用扩展事件获取Session级别的等待信息以及SQLServer 2016中Session级别等待信息的增强
本文出处:http://www.cnblogs.com/wy123/p/6835939.html 什么是等待 简单说明一下什么是等待:当应用程序对SQL Server发起一个Session请求的时候, ...
- [WPF] 动画Completed事件里获取执行该动画的UI对象
原文:[WPF] 动画Completed事件里获取执行该动画的UI对象 昨天群里有位童鞋提出如何在动画完成事件Completed里获取到执行该动画的UI对象. WPF里动画的Completed的本身并 ...
- WPF TreeView 选择事件执行两次,获取TreeView的父节点的解决方法
1.TreeView选择事件执行两次 Very often, we need to execute some code in SelectedItemChanged depending on the ...
- 运行page页面时的事件执行顺序
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- 转:运行page页面时的事件执行顺序及页面的回发与否深度了解
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- Oracle获取session的trace
1. 使用参数SQL_TRACE 下面是官网对此参数的说明 SQL_TRACE Property Description Parameter type Boolean Default value fa ...
- [Log]ASP.NET之HttpModule 事件执行顺序
ASP.Net下的HttpModule是基于事件的处理模型,这使得我们在选择事件监听和处理的时候有更多选择.下面是对HttpModule有关事件被触发的监测: 有关代码如下 using System; ...
- .net实现IHttpModule接口顾虑器
这篇文章主要介绍了C#使用IHttpModule接口修改http输出的方法,涉及C#操作IHttpModule接口的相关技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C#使用IHtt ...
随机推荐
- UESTC_Frozen Rose-Heads CDOJ 791
The winter is coming and all the experts are warning that it will be the coldest one in the last hun ...
- HDOJ-1014 Uniform Generator
http://acm.hdu.edu.cn/showproblem.php?pid=1014 给出式子seed(x+1) = [seed(x) + STEP] % MOD seed初始为0,给出STE ...
- 安全运维之:Linux系统账户和登录安全
一.合理使用Shell历史命令记录功能 在Linux下可通过history命令查看用户所有的历史操作记录,同时shell命令操作记录默认保存在用户目录下 的.bash_history文件中,通过这个文 ...
- hdu 5495 LCS
Problem Description You are given two sequence {a1,a2,...,an} and {b1,b2,...,bn}. Both sequences are ...
- C,C#,C++中&&和||,&和|的联系和区别
本文来自:http://www.cnblogs.com/GT_Andy/archive/2010/03/30/1921805.html 两者计算结果相同(针对各自的运算对象),只是性能上有差别而已. ...
- 检查ORACLE的警告文件的脚本
检查两天内的须要重视的信息: vi alter_error.sh echo "Check Alter Error:" cat $TRACE/alert_$ORACLE_SID. ...
- 移动平台前端开发总结(针对iphone,Android等手机)
移动平台前端开发是指针对高端智能手机(如Iphone.Android)做站点适配也就是WebApp,并非是针对普通手机开发Wap 2.0,所以在阅读本篇文章以前,你需要对webkit内核的浏览器有一定 ...
- 随学随记之java的数据类型
Java中的变量只有两种数据类型:基本数据类型(8种).引用数据类型 定义变量时内存中的状态变化:定义数据类型,开辟空间,存放数据. 8种基本数据类型的变量各占多大的内存空间,变量的取值范围 byte ...
- [AngularJS系列(4)] 那伤不起的provider们啊~ (Provider, Value, Constant, Service, Factory, Decorator)(转)
用AngularJS做项目,但凡用过什么service啊,factory啊,provider啊,开始的时候晕没晕?!晕没晕?!感觉干的事儿都差不多啊,到底用哪个啊?!别告诉我你们几个就是为了跟我炫耀兄 ...
- UVA 1212 Duopoly
题目: 两个公司进行投标,竞争一些channels,每个投标可以包含多个channels,且都有一定的收益,每一个channels只能为其中的一个公司利用,同时保证一个公司给出的投标中选中的chann ...