获得ASP.NET Cookieless Sessions和JQuery AJAX一起玩得很好 [英] Getting ASP.NET Cookieless Sessions and JQuery AJAX to play together nicely

查看:347
本文介绍了获得ASP.NET Cookieless Sessions和JQuery AJAX一起玩得很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用JQuery AJAX的网站。使用此JQuery代码

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



当使用 cookieless =false id 会显示在 Request.Form 中。当我设置 cookieless =true时, ID 不再位于 Request.Form 中。



UPDATE,我做了什么



我添加了对Response.ApplyAppPathModifier()的调用,以保留数据并避免自动重定向。我除了** Diago(和删除我自己,因为他的参考文献给出一些insite到发生了什么。我喜欢的独立域的想法,但我不能这样做。



以下是更新后的代码:

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

根据 MSDN Response.ApplyAppPathModifier()添加会话ID



由于没有会话ID,ASP.NET会创建一个新的会话并执行重定向(因此,剥离任何表单数据)。

解决方案

我最近遇到了同样的问题。这是使用cookieless会话的四个缺点之一。当击中服务器并且请求变量被删除时,请求被重写。当使用ASP.NET使用WebServices和POST请求时,这可能非常痛苦。这在使用GET时很好。



使用普通邮政会有类似的问题。有一篇文章这里介绍了如何做到这一点。 MSDN文章还详细讨论了缺点。



最佳解决方案是将您的服务放在单独的域或IIS虚拟站点上,而不使用无Cookie会话。



使用表单验证with cookieless会话也是一个有趣的挑战。


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).

解决方案

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.

这篇关于获得ASP.NET Cookieless Sessions和JQuery AJAX一起玩得很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆