我的环境,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 找了很多国内的都不对,从国外转过来一个测试可用的的更多相关文章

  1. 了解IHttpModule接口事件执行顺便 获取Session

    本文转载自:http://www.cnblogs.com/eflylab/archive/2008/05/29/1209767.html 最近公司一个项目让人SQL注入了-为了临时先解决这个问题,使攻 ...

  2. SQLServer中使用扩展事件获取Session级别的等待信息以及SQLServer 2016中Session级别等待信息的增强

    本文出处:http://www.cnblogs.com/wy123/p/6835939.html 什么是等待 简单说明一下什么是等待:当应用程序对SQL Server发起一个Session请求的时候, ...

  3. [WPF] 动画Completed事件里获取执行该动画的UI对象

    原文:[WPF] 动画Completed事件里获取执行该动画的UI对象 昨天群里有位童鞋提出如何在动画完成事件Completed里获取到执行该动画的UI对象. WPF里动画的Completed的本身并 ...

  4. WPF TreeView 选择事件执行两次,获取TreeView的父节点的解决方法

    1.TreeView选择事件执行两次 Very often, we need to execute some code in SelectedItemChanged depending on the ...

  5. 运行page页面时的事件执行顺序

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  6. 转:运行page页面时的事件执行顺序及页面的回发与否深度了解

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  7. Oracle获取session的trace

    1. 使用参数SQL_TRACE 下面是官网对此参数的说明 SQL_TRACE Property Description Parameter type Boolean Default value fa ...

  8. [Log]ASP.NET之HttpModule 事件执行顺序

    ASP.Net下的HttpModule是基于事件的处理模型,这使得我们在选择事件监听和处理的时候有更多选择.下面是对HttpModule有关事件被触发的监测: 有关代码如下 using System; ...

  9. .net实现IHttpModule接口顾虑器

    这篇文章主要介绍了C#使用IHttpModule接口修改http输出的方法,涉及C#操作IHttpModule接口的相关技巧,非常具有实用价值,需要的朋友可以参考下   本文实例讲述了C#使用IHtt ...

随机推荐

  1. python选择排序实现与C选择排序实现

    python代码: #coding=utf-8 if __name__=="__main__": arr=[3,2,1,7,11,4,5,8] print "Before ...

  2. HDU2037 贪心 动归均可+证明

    今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  3. 【转】VS2010中文注释带红色下划线的解决方法

    转载自:http://blog.csdn.net/whatday/article/details/7856323 环境:Visual Studio 2010 问题:代码中出现中文后会带下划线,很多时候 ...

  4. C++ 动态绑定

    1.为每一个包含虚函数的类设置一个虚表(VTABLE) 每当创建一个包含有虚函数的类或从包含虚函数的类派生一个类时,编译器就会为这个类创建一个VTABLE.在VTABLE中,编译器放置了这个类中,或者 ...

  5. 沼跃鱼早已看穿了一切 C/C++

      沼跃鱼早已看穿了一切 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 593  Solved: 229[Submit][Status][Web Boa ...

  6. 【转】mysql行列转换方法总结

    转:http://blog.chinaunix.net/uid-7692530-id-2567582.html 在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解 ...

  7. 【转载】MongoDB中的MapReduce 高级操作介绍

    转载自残缺的孤独 1.概述 MongoDB中的MapReduce相当于关系数据库中的group by.使用MapReduce要实现两个函数Map和Reduce函数.Map函数调用emit(key,va ...

  8. inline 间距

    今天看了内联元素的间距: http://blog.csdn.net/hedong37518585/article/details/6657853

  9. PHP记录点击数方法

    1.第一种方法: $id = $_GET['id']; //获取文章ID $sql = "UPDATE base SET hits = hits+1 WHERE id = '$id'&quo ...

  10. Python成长之路第二篇(2)_列表元组内置函数用法

    列表元组内置函数用法list 元组的用法和列表相似就不一一介绍了 1)def append(self, p_object):将值添加到列表的最后 # real signature unknown; r ...