Solved

URGENT:Problems with session state (asp.net  c#)

Posted on 2004-08-10
9
1,598 Views
Last Modified: 2008-01-09

hi can someone please explain the following and how i get round it please


Server Error in '/www' Application.
--------------------------------------------------------------------------------

Session state is not available in this context.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Session state is not available in this context.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[HttpException (0x80004005): Session state is not available in this context.]
   System.Web.HttpApplication.get_Session()
   www.Global.Application_Start(Object sender, EventArgs e)
 
___________________________________________________________________________________________
My Global.asax code is as follows

            protected void Application_Start(Object sender, EventArgs e)
            {
                  Session.Add("Lang","English");
            }
0
Comment
Question by:Robinsonx6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11762864
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11762887
Hi,
take at this discussion on the same problem ( it is very good ): http://www.dotnet247.com/247reference/msgs/41/206914.aspx

Regards,
B..M
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11762926
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
rohanpandya earned 250 total points
ID: 11762942
Hi

 it's true.

  when your application is start there is no session is avilable after your application is load after then your session is start so if you write session varialbe in the application_start method then it is not work b'cus session is not initialize.

 Best Luck.


 
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 11763039
hi again AeroSaga
Ok i think im being dumb but i have changed my code as follows:

            protected void Application_Start(Object sender, EventArgs e)
            {
                  HttpContext.Current.Session.Add("Lang","English");
            }

but i now get the following error:-

Server Error in '/www' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   www.Global.Application_Start(Object sender, EventArgs e)

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11763147
try putting that statement on the first page_load event of your application such as default.aspx instead.

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11763151
This one:

HttpContext.Current.Session.Add("Lang","English");
0
 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 250 total points
ID: 11763190
I believe that session has not started at that point currently and thus no session alteration is available

Aeros
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 11763191
ok big OOOPPPPSSS i put it in Application start not session start, my mistake thanks eveyone
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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