Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 405025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:21:43+00:00 2026-05-12T17:21:43+00:00

I have a problem with accessing values in the session through pagemethods. The example

  • 0

I have a problem with accessing values in the session through pagemethods.

The example below demonstrates the problem in a simple form. There are three buttons on the page and each of these invokes a different pagemethod, that, in turn accesses what I would expect to be the same variable from the session. In fact the value returned is different for each pagemethod, as demonstrated below.

I only get this problem when I deploy to the webserver; it’s not an issue when I test it locally.

Example output:

Method       Session Value
DoMethod1   597cbe1c-5391-4b93-af6b-0da0068b264b
DoMethod2   35df48aa-8a58-4008-b353-be7b9f950395
DoMethod3   35df48aa-8a58-4008-b353-be7b9f950395
DoMethod1   597cbe1c-5391-4b93-af6b-0da0068b264b
DoMethod2   597cbe1c-5391-4b93-af6b-0da0068b264b
DoMethod1   35df48aa-8a58-4008-b353-be7b9f950395
DoMethod3   35df48aa-8a58-4008-b353-be7b9f950395
DoMethod1   597cbe1c-5391-4b93-af6b-0da0068b264b
DoMethod2   597cbe1c-5391-4b93-af6b-0da0068b264b
DoMethod3   35df48aa-8a58-4008-b353-be7b9f950395




Imports System.Web.Services

Public Class MethodResult
    Public MethodName As String
    Public SessionID As String
    Public SessionValue As Object
End Class

Partial Public Class sessiontest
    Inherits System.Web.UI.Page

    <WebMethod()> _
    Public Shared Function DoMethod1() As MethodResult
        If HttpContext.Current.Session("sharedvalue") Is Nothing Then
            HttpContext.Current.Session("sharedvalue") = Guid.NewGuid
        End If
        Dim ret = New MethodResult
        ret.MethodName = "DoMethod1"
        ret.SessionID = HttpContext.Current.Session.SessionID
        ret.SessionValue = HttpContext.Current.Session("sharedvalue")
        Return ret
    End Function


    <WebMethod()> _
    Public Shared Function DoMethod2() As MethodResult
        If HttpContext.Current.Session("sharedvalue") Is Nothing Then
            HttpContext.Current.Session("sharedvalue") = Guid.NewGuid
        End If
        Dim ret = New MethodResult
        ret.MethodName = "DoMethod2"
        ret.SessionID = HttpContext.Current.Session.SessionID
        ret.SessionValue = HttpContext.Current.Session("sharedvalue")
        Return ret

    End Function


    <WebMethod()> _
    Public Shared Function DoMethod3() As MethodResult
        If HttpContext.Current.Session("sharedvalue") Is Nothing Then
            HttpContext.Current.Session("sharedvalue") = Guid.NewGuid
        End If
        Dim ret = New MethodResult
        ret.MethodName = "DoMethod3"
        ret.SessionID = HttpContext.Current.Session.SessionID
        ret.SessionValue = HttpContext.Current.Session("sharedvalue")
        Return ret

    End Function

End Class


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="sessiontest.aspx.vb"    Inherits="project1.sessiontest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
    <script type="text/javascript">
        function method1() {
            PageMethods.DoMethod1(methodComplete);
        }
        function method2() {
            PageMethods.DoMethod2(methodComplete);
        }
        function method3() {
            PageMethods.DoMethod3(methodComplete);
        }
        //complete
        function methodComplete(result) {
            document.getElementById('output').innerHTML += "<tr><td>" + result.MethodName + "</td><td>" + result.SessionID + "</td><td>" + result.SessionValue + "</td></tr>";
        }

    </script>    
    <div>
        <input type="button" value="Method 1" onclick="method1();" id="btn1" />
        <br />
        <input type="button" value="Method 2" onclick="method2();" id="Button1" />
        <br />
        <input type="button" value="Method 3" onclick="method3();" id="Button2" />
        <br />
        <table id="output" style="width:100%;">
            <tr>
                <th>Method Name</th>
                <th>Session ID</th>
                <th>Session Value</th>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:21:43+00:00Added an answer on May 12, 2026 at 5:21 pm

    You need to enable session state for your web methods.

    Example:

    <WebMethod(EnableSession:=True)> _
    Public Shared Function DoMethod1() As MethodResult
        If HttpContext.Current.Session("sharedvalue") Is Nothing Then
            HttpContext.Current.Session("sharedvalue") = Guid.NewGuid
        End If
        Dim ret = New MethodResult
        ret.MethodName = "DoMethod1"
        ret.SessionID = HttpContext.Current.Session.SessionID
        ret.SessionValue = HttpContext.Current.Session("sharedvalue")
        Return ret
    End Function
    

    check out this msdn article for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building my first ASP.Net MVC based app and have a problem accessing
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I do not have problem as such but I am quite new to Ruby.
I have a problem using the Java search function in Eclipse on a particular
I have a problem with a little .Net web application which uses the Amazon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.