在Global.asax、HttpModule中使用Session
经测试,可以在AcquireRequestState、PreRequestHandlerExecute事件中处理Session
Global.asax部分代码
void Application_AcquireRequestState(object sender, EventArgs e)
{
string str = HttpContext.Current.Session.SessionID;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
string str = HttpContext.Current.Session.SessionID;
}
一个实现IHttpModule的类的部分代码
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
string str = HttpContext.Current.Session.SessionID;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void context_AcquireRequestState(object sender, EventArgs e)
{
string str = HttpContext.Current.Session.SessionID;
}
Global.asax部分代码
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
一个实现IHttpModule的类的部分代码
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)