views:

1397

answers:

2

I have a web site that uses JQuery AJAX. With this JQuery code

$.post("/ajax/getsomedata.aspx", {'id': id }, 
    function(data) 
    {
        dosomething(data);
    }
);

When I run this with cookieless="false", id shows up in Request.Form. When I set cookieless="true", id is no longer in Request.Form.

UPDATE, What I did

I added a call to Response.ApplyAppPathModifier() to preserve the data and avoid an automatic redirect. I am excepting **Diago(( and deleting my own because his references give some insite into what's going on. I like to idea of the seperate domain, but I can't do that here.

Here's the updated code:

$.post("<%=Response.ApplyAppPathModifier("/ajax/getsomedata.aspx")%>", 
        {'id': id },
    function(data)     
    {        
        dosomething(data);    
    }
);

According to MSDN Response.ApplyAppPathModifier() adds the session id if you are in cookieless session state, and returns the unaltered URL if you are not.

Since there is no session id, ASP.NET creates a new session and does a redirect (thus stripping off any form data).

A: 

You will have to include the session token in your request. ASP.Net must be adding it in either the url or hidden form fields. Grab it and add it jquery parameter object. That's as far as I can say coz i have never coded in ASP.NET

Tahir Akhtar
+1  A: 

I struggled with the same problem recently. This is one of the four drawbacks of using cookieless sessions. The request is rewritten when hitting the server and the request variables are dropped. This can be extremely painful when using WebServices and POST request using ASP.Net. This works fine when using GET.

You will have a similar problem using normal post. There is an article here that explains how it can be done. This MSDN article also discusses the drawbacks at length.

The best solution is to put your services on a seperate domain or IIS Virtual site not using cookieless sessions.

Using Forms Authentication with cookieless sessions is also an interesting challenge.

Diago