Posted: 8/22/2011
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
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');
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>
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"; } } }