DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2005
    Posts
    91

    Question Use Session variables in Global.asax

    Hi People,

    I want to share Session variables through out all the aspx pages including Global.asax. I have tried placing Session variables into the Global.asax page and it doesn't seems to work.

    The Session variables should start as empty variables. When a button has been pressed on a particular page it should update the Session variables and Global.asax will compare the variables everytime the user has press a button/refresh a page.

    Could this be possible? Can someone help me out here

    Thanks

    kero
    Last edited by kero; 09-16-2005 at 05:06 AM.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Please post ASP.NET questions to the ASP.NET forum, rather than .NET Technical. Thank you!

    Can you please post a small code sample demonstrating the problem you're having?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2005
    Posts
    91
    Hi Phil,

    I want to place the following code to Global.asax, but I'm not sure where? I have a one which is smiliar to the following codes in Application_AuthenticateRequest() section.
    Code:
            If (Session("userNameUpdated") = "true") Then
                ' -- connecting to the database and setting a SQL command.
                Dim myConnection As New SqlConnection(connectionString)
    
                ' -- Declare SqlCommand variable to be used on different database
                Dim storeProcedure As String
                Dim rolesCommand As SqlCommand
                Dim roleList As New ArrayList
    
                storeProcedure = "spUserRole '" & Session("Email") & "'"
    
                Try
                    myConnection.Open()  ' -- Connect to the database
                    Dim reader As SqlDataReader = rolesCommand.ExecuteReader()
    
                    ' -- Create an array of role names
                    Do While reader.Read()
                        roleList.Add(reader("Role"))
                    Loop
                    reader.Close()
    
                Catch SQLexc As SqlException
                    SQLexc.ToString()
    
                Catch ex As Exception
                    ex.ToString()
    
                Finally
                    myConnection.Close()  ' -- Close to the database
    
                End Try
    
    
                '-- Convert the roleList ArrayList to a String array
                Dim roleListArray As String() = roleList.ToArray(GetType(String))
    
                Dim myIdentity As New GenericIdentity(Session("Email"))
                HttpContext.Current.User = New GenericPrincipal(myIdentity, roleListArray)
                Session("userNameUpdated") = "false"
            End If
    I have used User.Identity in the Application_AuthenticateRequest() instead of Session("EMail"). The Session("userNameUpdated") And Session("EMail") won't work on Application_AuthenticationRequest(). I need to find a way to compare session variables that has been updated or not

    Please help

    Thanks

    kero
    Last edited by kero; 09-16-2005 at 06:42 AM.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Does the code work in Authenticate_Request? What problem are you having?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Feb 2005
    Posts
    91
    Hi Phil,

    I can't get the session working. I need to check against session when someone update their Username from the update form and press the save button

    kero
    Last edited by kero; 09-16-2005 at 07:22 AM.

  6. #6
    Join Date
    Feb 2005
    Posts
    91
    The code works with out session in AuthenticateRequest part, but as soon as I have placed session in AuthenticateRequest it gives me an errror message saying that session is not available in this context
    Last edited by kero; 09-16-2005 at 07:24 AM.

  7. #7
    Join Date
    Feb 2005
    Posts
    91
    How do I make a Global variable so I can share with aspx and the Global.asax pages?

    Please help

  8. #8
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    See if this helps: http://dotnet247.com/247reference/msgs/45/227112.aspx

    I found it by searching for "asp.net session authenticaterequest not available context".
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  9. #9
    Join Date
    Feb 2005
    Posts
    91
    Thanks Phil,

    I will try it out later and let you know does it work. If it doesn't work I will store the updated userName to a temp variable first. When the session ends the userName will be updated to the database.

    Kero

  10. #10
    Join Date
    Feb 2005
    Posts
    91
    Hi Phil,

    Do you know how to place a cache in Global.asax?

    Kero

Similar Threads

  1. Replies: 12
    Last Post: 02-07-2012, 01:34 PM
  2. releasing session variables
    By Matt Markus in forum ASP.NET
    Replies: 3
    Last Post: 06-16-2003, 05:48 PM
  3. All Session Variables
    By Pierre in forum ASP.NET
    Replies: 0
    Last Post: 03-28-2002, 12:32 PM
  4. passing Session variables in Form
    By Bill Heffner in forum ASP.NET
    Replies: 0
    Last Post: 11-13-2001, 05:34 PM
  5. Lose of Session variables
    By Yang Du in forum ASP.NET
    Replies: 2
    Last Post: 10-26-2001, 10:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links