[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-12
6
Medium Priority
?
2,231 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:tedporter
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:Tristan Shortland
ID: 22938717
Try using HttpContext.Current.Session("Value") to ensure you have the current context...
0
 

Author Comment

by:tedporter
ID: 22938756
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
 

Author Comment

by:tedporter
ID: 22938769
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 4

Expert Comment

by:Tristan Shortland
ID: 22938979
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
 

Accepted Solution

by:
tedporter earned 0 total points
ID: 22939119
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
 

Expert Comment

by:aemekli
ID: 25558651
Thanks for explanation
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question