Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 25th, 2007, 02:25 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session state error

Session state can only be used when enableSessionState is set to


My code is this
 Private userID As Integer = Session("UserID")

    Private FileNamePath As String = System.Configuration.ConfigurationManager.AppSetti ngs.Get("MyDirPath") _
    & userID & "_" & String.Format("MMddyyy", DateTime.Today) & ".txt"
gives me an error. I put enabled Session State = true in page directive. Second error could not figure out. My web config is described after the error
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.

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <connectionStrings>
        I have connection string here
    </connectionStrings>

  <appSettings>

   My appsettings are here
  </appSettings>












  <system.web>

    <roleManager enabled="true" />
    <pages enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false"/>









    <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true">
            <assemblies>
                <add assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies></compilation>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows"/>
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>



  #2 (permalink)  
Old July 25th, 2007, 02:30 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am not sure I understand what you're posting here.

Are you making a statement?? This seems to say you are:
Quote:
quote:Session state can only be used when enableSessionState is set to
Or are you asking a question? Are you maybe getting an error because Session state is not configured? Look at the error:
Quote:
quote: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
Isn't that as clear as it gets?

Anyway, if you post follow up or new questions, you may want to spend some time to explain what it is you really want. Saves us from a lot of confusion.... ;)

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old July 25th, 2007, 03:37 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am trying to get the value of which I have set in login page. when I try to use it outside the events say declared it globally then it gives an error other wise If i used it locally inside the event, it gives value Session("userID)

  #4 (permalink)  
Old July 25th, 2007, 09:27 PM
Friend of Wrox
 
Join Date: Feb 2006
Location: , , USA.
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I recommend you double check that it is actually being set in the login page. For example, if you were using HttpContext.Current.User.Identity.Name to access the logged in user name, that is not available until after a post back, which means it's not available in the page_load event handler of the login page. Same goes for User.Identity.Name and Context.User.Identity.Name which are all the same thing. As far as I know one workaround is:

Code:
Dim username As String = CType(Login.FindControl("UserName"), TextBox).Text
In page_load you don't know if it was authenticated or not so keep that in mind. However if you handle say, the login controls LoggedIn event and put that in there then thats a safe assumption, and you can use that to set stuff like session vars.
  #5 (permalink)  
Old July 25th, 2007, 09:41 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually after the user logins I set the user ID, then after post login, I try to use Session(User(ID") but it complains

  #6 (permalink)  
Old July 25th, 2007, 10:28 PM
Friend of Wrox
 
Join Date: Feb 2006
Location: , , USA.
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure.

But I do know when you access the session collection, you always have to check if it's Nothing, because session state is not reliable, especially if you are using the default InProc session state service. The app pool can get recycled any time by IIS when memory reaches some limit, and then you lose session state values. Thus you have to program against it with that in mind. I'm not saying thats your problem here, but it's worth keeping in mind.
  #7 (permalink)  
Old July 26th, 2007, 10:57 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It complains at top not on page load, gives value on page load for session
Private userID As Integer = Session("UserID")
    Dim rightNow As DateTime = DateTime.Now
    'Private FileNamePath As String = "_" & System.Configuration.ConfigurationManager.AppSetti ngs.Get("MyDirPath")

    Private FileNamePath As String = "data _" & rightNow.ToString("yyMMdd_hhmmss") & userID & ".txt"
    Private objStreamWriter As System.IO.StreamWriter

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            Dim userID As Integer
            userID = Session("UserID")

  #8 (permalink)  
Old July 26th, 2007, 11:21 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you define "complains"? Do you get an error?

Again, it would be really helpful if you provided more information. We can't look at your IDE or even your site, so it's hard for us to see what's going on. The more information you provide, like an error message instead of just saying it complains, would really help....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #9 (permalink)  
Old July 26th, 2007, 11:41 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 the error is as follows. I have enabledSession= true in page directive. My web config is also shown below
 enabled Session State = true in page directive. Second error could not figure out. My web config is described after the error
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.

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <connectionStrings>
        I have connection string here
    </connectionStrings>

  <appSettings>

   My appsettings are here
  </appSettings>












  <system.web>

    <roleManager enabled="true" />
    <pages enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false"/>









    <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true">
            <assemblies>
                <add assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies></compilation>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows"/>
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>




  #10 (permalink)  
Old July 26th, 2007, 12:09 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

This is not a proper description of the error, but merely a copy and paste action of your original post, with identical spelling / writing mistakes still in them.

Where do you get this error? In the browser or at development time? Can you provide more detail about your code, site, and setup?

I can get the information out of you by asking questions one by one, where you respond by copying the same post over and over again. My guess is that this can take days....

As an alternative, you could provide a *useful* description of your situation, provide *relevant* information about errors, setup and so on so we can help you resolve this in a few minutes.

Your call......

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session State Problem? caterpillar ASP.NET 1.0 and 1.1 Basics 8 August 17th, 2006 03:08 PM
Session State|View State|Do I have other options? rockon ASP.NET 1.x and 2.0 Application Design 2 October 5th, 2005 07:10 PM
maintaining session state in C# grs General .NET 0 January 13th, 2005 03:46 AM



All times are GMT -4. The time now is 06:58 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.