需要在Global.asax.cs当中重载Init方法:
1
2
3
4
5
|
public override void Init()
{
PostAuthenticateRequest+=SessionOpen;
base.Init();
}
|
这里的SessionOpen是一个委托,方法签名为:
1
|
void Action(object sender,EventArgs e);
|
即:
1
2
3
4
|
private void SessionOpen(object sender,EventArgs e)
{
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
}
|