Showing posts with label Web Application. Show all posts
Showing posts with label Web Application. Show all posts

Thursday, September 10, 2009

ASP.NET Session state is not available in the current context

I actually ran into the issue discribed in Siderite Zackwehdex's Blog: Session state is not available in the current context

An almost duplicate reprint of his article with my own specific account wired in follows ...

An ASP.Net web site that was recently switched to ASP.Net 3.5 and is suddenly returning "Sys is undefined"
Upon entering the url of the offending item into the browser address bar the ASP.Net error page displays "Session state is not available in this context.".

The reason - in global.asax - code was attempting to work with Session.
The error was returned by the Session property of the HttpApplication object, the one that the global.asax file represents!

First mistake: there was Session property available and it was immediately assumed that is the same as Page.Session or HttpContext.Current.Session. While the HttpApplication Session is nearly identical, it throws an error if the underlying Session object is null.

Ok, but why is Session null? You are a smart .Net developer and you know that the Session should be available in that event. Any documentation says so! Well, yes, but it applies to your page, not to all the IHttpHandler implementations, like the ScriptResource.axd! The css and image problems only occured for me only when seeing the site in Cassini, not in IIS, so maybe it opens separate threads to load those resources and ignores the session or something, at least at that level.

Well, how does one fix it? Adding in global.asax a condition on Session not being null throws the same error. Ok, then add it on HttpContext.Current.Session. In other words:

if (HttpContext.Current.Session!=null) //do stuff with sessions.

Maybe this problem occurs in other places as well, but only the Session property of the HttpApplication will throw the "Session state is not available in this context." error.

Wednesday, July 18, 2007

Web Application Project

After working for a while to get this Converted ASP.NET 2.0 VS.Net 2005 VB.Net 2005 (8.0) Application to completely build, I ran into Parser Error Message: Could not load type '.Global'.

I am searching everywhere and find this refference
http://forums.aspfree.com/net-development-11/parser-error-message-could-not-load-type-17894.html
http://forums.aspfree.com/showpost.php?p=60570&postcount=13
================================================================
March 23rd, 2004, 11:03 AM
manos

Registered User
Join Date: Mar 2004
Location: Canada
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0

I found another answer

--------------------------------------------------------------------------------

Hi, just thought I'd share my answer to this frustrating problem.

Basically what I found was that for some reason, the class names that my .aspx pages where inheriting from were wrong. What happened
was that when checking the project in to source control, I had actually named my solution "Something.Net". This meant that all my
code behind inheritance directives said "Something.Net.class". (i.e. Something.Net._default) This may have been a problem.

When I noticed that, I recreated the solution as just "Something" and copied the files from the old solution. I then had to go in to the .aspx files
and change the page directives so that the pages inherited from Something._default.

After that it worked fine.

Good luck.

==========================================================================

I say to myself, "Oh, )&(^*&%(&*)(>, I remember having to change the application name. So, I open a code file in VS.NET 2005 and type Imports . And sure enough no Global ... then I remember some of my components seem to have dropped a level so I type .. and ther is my GLOBAL.
I open 1) Global.asax in NotePad, 2) change the Inherits=".Global" to Inherits="..Global" 3) Save & Close the file 4) rebuild the project
It worked ...
Now why in the code does my project have a split class set with some classes under and others under .????

And onto other Parse Errors ...