473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

External Assembly accesing Session generates an error

I have a WebSite "App1" which has an external assembly "Lib1".

Inside this external assembly we have developed some classes that derive
from "System.Web.UI.Page". One of these pages is called "WebNotification".

In the WebSite "App1" we create an instance of "WebNotification", but when
this class tries to access some Session variables it generates the following
error:

Session state can only be used when enableSessionState is set to true,
either in a configuration file or in the Page directive. Please also make
sure that System.Web.SessionStateModule or a custom session state module is
included in the <configuration>\<system.web>\<httpModules> section in the
application configuration.

I have tried to write "EnableSessionState= true" in the web.config and even
in the <%page%> directive but the error is still there.

Why?
Is there any restriction about accesing Session variables from class defined
in an external library?
Is there anyway to avoid this?
May 16 '06 #1
2 2052
Since you are most likely instantiating this class in code, you can create a
constructor or properties and pass the session magic to the page prior to
displaying it. Treat an external library like a black box and it will be
your friend.

You can also go down into the bowels and get the session state object and
pull that way, provided the class has the proper context at the point you
are attempting to get session items. You will have to pull session state
from application, which comes from context, which means you have to be far
enough into the process to have context for the application, but it should
be easy enough to do with some digging I do not have any sample code for
this and I do not consider this the better option.

I just recently dealt with some code where all sorts of magic was going on,
including pulling session variables and config items. It was a straight
library (not inherited from an ASP.NET object), so it was easier to get into
this madness (no blow ups). It was not discovered until the population of
variables was moved from config to the database. Since the config element
was now controlled by user configurable metadata (in the DB), it was removed
from the config file and boom. A few refactors later and the class no longer
reached outside of its domain (i.e., it was a black box used by a web app).
Long term benefit: You can switch to a windows GUI in the future without
having to tackle the madness.

Overall, I am not fond of compiled libraries that handle GUI bits, but I can
see where reusability might dictate this functionality. And, you might have
to pull things from config or session in these objects, as they cannot move
to other GUI types (i.e., they are tightly coupled to the web solution, no
matter what). If, however, you move to a model where there is a GUI facade
and the GUI bits only handle display (and perhaps basic validation), you
find there is less need to create pure GUI libraries as the work is all done
behind the scenes.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
"ras26" <ra***@newsgroup.nospam> wrote in message
news:EC**********************************@microsof t.com...
I have a WebSite "App1" which has an external assembly "Lib1".

Inside this external assembly we have developed some classes that derive
from "System.Web.UI.Page". One of these pages is called "WebNotification".

In the WebSite "App1" we create an instance of "WebNotification", but when
this class tries to access some Session variables it generates the
following
error:

Session state can only be used when enableSessionState is set to true,
either in a configuration file or in the Page directive. Please also make
sure that System.Web.SessionStateModule or a custom session state module
is
included in the <configuration>\<system.web>\<httpModules> section in the
application configuration.

I have tried to write "EnableSessionState= true" in the web.config and
even
in the <%page%> directive but the error is still there.

Why?
Is there any restriction about accesing Session variables from class
defined
in an external library?
Is there anyway to avoid this?

May 16 '06 #2
Thanks for your alternative solutuions, but I have already found what was
wrong.

We were trying to access the Session variable in the constructor of the
derived page in the library.

At this time, Session is not available, so we have move the code to the
onInit event and all works ok.

Anyway thanks again for your answer.

May 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Edward Diener | last post by:
This has occurred in MC++, but since there is very little response on that NG, I am also reporting it here in the hope that someone can find me a workaround, and report it to MS. If a __value...
9
by: keith | last post by:
I created a class libery which has name space Assembly and class Assembly and compiled it. Then created a C# project and called a method in the external class e.g. Assembly dll;...
6
by: wASP | last post by:
Hello everyone, I'm new to C# and ASP.NET, so pardon my stupidity on this one. I'm having a problem with referencing methods/functions external to a class member function. My code is as...
0
by: test.file | last post by:
We have an application that is running under Citrix. The application files are located on a shared network drive and the app is launched via UNC. The app contains WinForms that are called from...
0
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
0
by: Laquesis | last post by:
What?: I'm getting this: "Method 'CreateObject' in type 'Microsoft.Practices.EnterpriseLibrary.Data.DatabaseCustomFactory' from assembly 'Microsoft.Practices.EnterpriseLibrary.Data,...
0
by: Andrea Anastasescu | last post by:
Hi everybody, Inside the web.config of my application I have some custom sections. I have my own handlers for these sections, and their content is in external files. My problem is that...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
1
by: neoupadhyay | last post by:
External component has thrown an exception. C:\Program Files\Microsoft Visual Studio 8\Common7\IDE> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.