Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET Session Error - Session State can only be used when...

Posted on 2009-04-06
4
Medium Priority
?
393 Views
Last Modified: 2012-05-06
I get this 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.

when I run my category.aspx page.  In my page decleration I have:
<%@ Page Language="VB" MasterPageFile="~/CatVend.master" AutoEventWireup="false" CodeFile="category.aspx.vb" Inherits="category" title="Untitled Page" EnableSessionState="True" %>

When i run category.aspx i hangs with the error above at:
Public Class category
    Inherits System.Web.UI.Page
-->    Public CatID As Integer = CType(Session("CatID"), Integer)

I've looked online for the answer and how to change the settigns in the web.config file, but what i've tried hasn't worked.

I also setup the Session("CatID") in the Global.asax file like this:

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        Session("CatID") = 0
    End Sub

But that didn't work.  Session("CatID") gets set on a previous page - and I'm able to apply the value to it just fine.  Not sure what i'm doing wrong.

Thanks for your help!
0
Comment
Question by:steverguy
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 24081180
do you have EnableSessionState="True" on your master page?
0
 
LVL 1

Author Comment

by:steverguy
ID: 24081298
no, just on the page that called the master page... i'll give that a try and let you know.  thanks!
0
 
LVL 16

Accepted Solution

by:
burakiewicz earned 2000 total points
ID: 24081419
yeah, im thinking the master page might be overridding it
0
 
LVL 1

Author Comment

by:steverguy
ID: 24082202
It turns out I just had to move the CatID = Session("CatID") into the pageload sub.  after i did that, it worked.  I had the session coming in where my other declerations were.

Thanks for your help!
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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 …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

927 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