Session state is not available in this context - Only When Debugging

Hi,

I have an Application_Error handler that collates various information. Part of this information includes Session variables e.g. string Username = "Username: " + Session["UserName"];

This all works fine except if I want to trace program code in the VS2008 debugger. I then get the error "Session state is not available in this context" when it reaches this line.

Thank you,


Ted.
tedporterIT Technical Services ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tristan ShortlandCommented:
Try using HttpContext.Current.Session("Value") to ensure you have the current context...
0
tedporterIT Technical Services ConsultantAuthor Commented:
Hi,

Thanks for the suggestion. I have tried it and now get a new error message

System.NullReferenceException was unhandled by user code

As previously mentioned, the code works fine in Production just not when debugging.
0
tedporterIT Technical Services ConsultantAuthor Commented:
Hi All,

This might help - The original error also contained the following:

System.Web.HttpException was unhandled by user code
  Message="Session state is not available in this context."
  Source="System.Web"
  ErrorCode=-2147467259
  StackTrace:
       at System.Web.HttpApplication.get_Session()
       at ASP.global_asax.Application_Error(Object sender, EventArgs e) in d:\Documents and Settings\EPorter\My Documents\My Code\Visual Studio 2008\WebSites\eNjoin\Global.asax:line 41
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Web.HttpApplication.RaiseOnError()
  InnerException:
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tristan ShortlandCommented:
Are you debugging a class library stand-alone? You need to launch it from a test web app if you are, so that the web context is available...
0
tedporterIT Technical Services ConsultantAuthor Commented:
Hi,

I fixed my problem. It was to do with my web menu (Coalesys Mecury UI) control, using a hidden menu that was referencing some GIF images that were not present.

Not sure why this ony raised it head in debug mode and not in release but I took the references out and it now debugs fine.

I will let the guys over at Coaleysy know.

Thanks for you help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aemekliCommented:
Thanks for explanation
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.