EnableSessionState again

This is a really confounding error: I cant seem to get the Session property on an aspx page to work. It keeps returning me the msg that
 System.Web.HttpException: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive

Source Error:
 Session("selectedVal")=dropdownName.SelectedItem.text.ToString()

I have set up a page directive and also have set it up to be true in the web.cofig but to no avail.

ANy clues to the error are appreciated.This is supposed to be so easy yet.......

thanx
LuckyLucksAsked:
Who is Participating?
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.

hismightinessCommented:
If what you say is true and the settings are set in those places then this shouldn't be happening.  I have placed this solution on a few posts already, but updating the Framework service pack from Microsoft fixed a great deal of little "bugs" I was experiencing in a number of my applications.

Framework v1.1 Service Pack 1:
http://www.microsoft.com/downloads/details.aspx?FamilyID=a8f5654f-088e-40b2-bbdb-a83353618b38&DisplayLang=en

Service Pack 2:
http://www.microsoft.com/downloads/details.aspx?FamilyID=75b0bc1d-c26c-4bac-ac68-2b4d431cabb5&DisplayLang=en

One thing to keep in mind is that usually the network admins or the user keeps the development machines up to date with Windows Update, but this is not always the case with our web servers.  So, if you updated your machine(s) and not the web server, this is the least of the problems you will run into.  

Once you rebuilt a project and deploy it on an updated machine and then deploy it to the web server, you might as well make yourself comfortable, because your visitors will begin getting all kinds of weird and unnecessary errors.  
0
gadget27Commented:
I've had the same problems in the past when trying to use Session variables outside functions (like in the class variable declarations such as 'Dim str as String = Session("theString")'. I was always able to rework the logic to keep such uses of Session variables inside functions. I dont know if this applies to your situation, but I thought I'd throw that out there for you just in case.
0
LuckyLucksAuthor Commented:
Do I need the SP2? Oddly the service pack 2 came 2 years after SP1.Is this a typo?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

hismightinessCommented:
Just do the Windows Update if you can.  The 2nd service pack confuses me too.
0
RejojohnyCommented:
is ur session maintained using cookie .. do u have this line in the web.config file ...
<sessionState
      cookieless="false"
      timeout="20"
              ......

if yes, then is cookie enabled on the browser u r testing?

r session working on other pages of the same project? if yes, then the problem must be very spedicifc to this page and we can concentrate on it ...
0
LuckyLucksAuthor Commented:
I didnt have the sessionState enabled in the web.config file. I am going to try this fix on Friday when I return to work. I'll post if it helped.
thanx
0
LuckyLucksAuthor Commented:
Public Class TopForm
    Inherits System.Web.UI.Page
    Public WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Public WithEvents Label1 As System.Web.UI.WebControls.Label
   
    Public Dim name As String
No, nothing seems to work :-(

I applied SP1 to the IIS server and added the sessionState tag to the web.config which looks like:
  <sessionState mode="InProc"
                        cookieless="false" timeout="20" />

Yet the Session doesnt work. Sill gives me the error:
System.Web.HttpException: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive


Public Sub TextBox1_TextChanged(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Label1.Text = "I was clicked at: " & System.DateTime.Now
       
        Session.Add("Name",TextBox1.text.ToString())

End Sub

Public Sub getName()
   name=TextBox1.text    
End Sub

End Class

Any clues will be appreciated
0
LuckyLucksAuthor Commented:
No, nothing seems to work :-(

I applied SP1 to the IIS server and added the sessionState tag to the web.config which looks like:
  <sessionState mode="InProc"
                        cookieless="false" timeout="20" />

Yet the Session doesnt work. Sill gives me the error:
System.Web.HttpException: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive

Public Class TopForm
    Inherits System.Web.UI.Page
    Public WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Public WithEvents Label1 As System.Web.UI.WebControls.Label
   
    Public Dim name As String
Public Sub TextBox1_TextChanged(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Label1.Text = "I was clicked at: " & System.DateTime.Now
       
        Session.Add("Name",TextBox1.text.ToString())

End Sub

Public Sub getName()
   name=TextBox1.text    
End Sub

End Class

0
hismightinessCommented:
Is this just a generic error, or does it give you a line of code where it occurs?

This is the default VS.Net SessionState XML:

<sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false"
            timeout="20"
/>

Have you tried this?  I don't know a whole lot about the specifics in the this particular tag, but it works for everything I have needed to do in a multitude of projects.

MODE - [InProc|SQLServer] (I think).  It depends on where you are wanting to store the session state.
STATECONNECTIONSTRING - I dunno...
SQLCONNECTIONSTRING - I dunno...
COOKIELESS - [true|false] Do you want to use cookies or store session state in the URL?
TIMEOUT - The time (in minutes) that a session will last.
0
hismightinessCommented:
Actually, I do know the other two...

STATECONNECTIONSTRING - This specifies how it will store sessionstate on the local machine if you chose InProc for the mode, otherwise it is ignored.
SQLCONNECTIONSTRING - This specifies where to store sessionstate if you chose SqlServer for the mode, otherwise it is ignored.
0
RejojohnyCommented:
have u had a look at the machine.config file .. anyway whatver the settings in that file should have get overwritten by the setting of the web.config file of the project .. that is the reason i didn't mention it before .. anyway, just have a look ...
0
RejojohnyCommented:
try this ..
use System.Web.HttpContext.Current.Session instead of the "session"
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
RejojohnyCommented:
if the above suggestion does not work .. then
have a look at this
http://www.visual-basic-data-mining.net/forum/ShowPost.aspx?PostID=376

same problem as urs .. lots of suggestion .. am sure one of them will be approriate for u ...
0
hismightinessCommented:
Rejojohny, looking in the Machine.Config is a waste of time.  As you said, the Web.Config will overwrite the setting(s) unless something is explicitly made to not be  overwritten, but that has to be done manually.
0
RejojohnyCommented:
hismightiness, i agree and that is what i wrote when i made the suggestion ..
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.