获取ASP.NET Cookie会话和jQuery AJAX一起玩的很好 [英] Getting ASP.NET Cookieless Sessions and JQuery AJAX to play together nicely

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

问题描述

我有一个使用JQuery的AJAX的Web站点。有了这个jQuery code

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

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

当我运行这个是无cookie =假 ID 显示在的Request.Form 。当我将无cookie =真正的 ID 不再的Request.Form

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.

更新,我所做

我添加了一个调用Response.ApplyAppPathModifier(),以preserve数据,避免自动重定向。我除外** DIAGO((和删除我自己,因为他的引用给一些INSITE到这是怎么回事,我喜欢到单独的域的想法,但我不能这样做,在这里。

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.

下面是更新后的code:

Here's the updated code:

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

据<一href="http://msdn.microsoft.com/en-us/library/system.web.htt$p$psponse.applyapppathmodifier.aspx">MSDN Response.ApplyAppPathModifier()补充说,如果你是在Cookie的会话状态的会话ID,并返回未改变的URL,如果你不是。

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.

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

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

推荐答案

我有同样的问题,最近在努力。这是四大弊端使用Cookie会话之一。击中服务器请求时改写和请求变量被丢弃。这可以通过使用Web服务和POST请求使用ASP.Net的时候是非常痛苦的。这种使用GET时工作正常。

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.

您将使用常规的后类似的问题。这里有文章 ,解释它是如何可以做到的。 MSDN文章还详细讨论了该缺陷。

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.

最好的解决办法是把你的服务在一个单独的域或IIS虚拟站点不使用Cookie会话。

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

使用窗体身份验证与Cookie会话也是一个有趣的挑战。

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

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

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