Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

EnableSessionState again

Posted on 2004-11-30
15
Medium Priority
?
205 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:LuckyLucks
  • 5
  • 5
  • 4
  • +1
15 Comments
 
LVL 9

Expert Comment

by:hismightiness
ID: 12706895
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
 
LVL 3

Expert Comment

by:gadget27
ID: 12709186
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
 

Author Comment

by:LuckyLucks
ID: 12709979
Do I need the SP2? Oddly the service pack 2 came 2 years after SP1.Is this a typo?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:hismightiness
ID: 12710797
Just do the Windows Update if you can.  The 2nd service pack confuses me too.
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12714124
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
 

Author Comment

by:LuckyLucks
ID: 12718435
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
 

Author Comment

by:LuckyLucks
ID: 12739329
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
 

Author Comment

by:LuckyLucks
ID: 12739343
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
 
LVL 9

Expert Comment

by:hismightiness
ID: 12739669
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
 
LVL 9

Expert Comment

by:hismightiness
ID: 12739697
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12747009
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
 
LVL 26

Accepted Solution

by:
Rejojohny earned 2000 total points
ID: 12747018
try this ..
use System.Web.HttpContext.Current.Session instead of the "session"
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12747036
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
 
LVL 9

Expert Comment

by:hismightiness
ID: 12748502
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12751474
hismightiness, i agree and that is what i wrote when i made the suggestion ..
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

580 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