Loading ...

PageMethod in masterpage is not working if I set the sessionstate to cookieless

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  asp.net ajax   » PageMethod in masterpage is not working if I set the sessionstate to cookieless

PageMethod in masterpage is not working if I set the sessionstate to cookieless

Posts under the topic: PageMethod in masterpage is not working if I set the sessionstate to cookieless

Posted: 8/22/2011

Lurker 5  points  Lurker
  • Joined on: 11/18/2010
  • Posts: 1

Hi,

I have a web application which uses a pageMethod in the master page. It works fine without anyproblem.

I want the application to be cookieless. So I set the sessiostate cookieless=true. After that the pageMethod is not firing. If comment the <sessionstate> tag in the web.config file then the PageMethod works fine. Can anyone tell me what the problem is and how to solve this issue.

Thanks in advance

Ajith


Posted: 8/23/2011

Guru 16773  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Hi,

Without cookieless true the url which will be called via PageMethod will be like this:
http://localhost:5124/Test.aspx/TestMethod

Cause of the issue: In cookieless true mode the script proxy generated sets the page path to '/Test.aspx' i.e forward slash is added which will break the PageMethod. To fix the issue you need to set the page name manually just above you are calling your pagemethod:

 PageMethods.set_path('test.aspx'); 
This will lead to following url: 

http://localhost:5124/(S(qkqxumqk02us0055wpmbay45))/test.aspx/TestMethod 

Sample code:
ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApplication2.test" %>

<!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" EnablePageMethods="true" EnablePartialRendering="true"
        runat="server" />
    <div>
    </div>
    
    </form>
</body>
<script language="javascript">

    function CallPageMethod() {
        PageMethods.TestMethod(onSucceeded, onFailed);
    }

    function onSucceeded(result, userContext, methodName) {
        alert(result);

        //success
    }
    function onFailed(error, userContext, methodName) {
        //failure
    }

    PageMethods.set_path('test.aspx'); 
    
    CallPageMethod();
    </script>
</html>

C#:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication2
{
    public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [System.Web.Services.WebMethod(EnableSession = true)]
        [System.Web.Script.Services.ScriptMethod()]
        public static string TestMethod()
        {
            return "hello";
        } 

    }
}


Page 1 of 1 (2 items)