Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

c# - What is the first global.asax event that Session is accessible assuming the context handler is IRequiresSessionState or IReadOnlySessionState?

My app sometimes calls Server.Transfer in the Application_OnPostAuthenticateRequest event of the global.asax to act as kind of url rewite. When this happens and I need to access Session I get an HttpException: "Session state can only be used when enableSessionState is set to true..." I am assuming this is happening because of the event I am calling Server.Transfer. Is that why I am getting the exception? When should I do the transfer?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The PostAuthenticateRequest occurs before the AcquireRequestState and the session state should only be available after this event is raised, so if you need to access session state for the request you need to wait for that event.

See this page as a reference.

  1. ...
  2. Raise the PostAuthenticateRequest event.
  3. ...
  4. Raise the AcquireRequestState event.
  5. ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...