【问题标题】:What is eating my cookie?! Cookie does not get transferred in asmx call什么在吃我的饼干?! Cookie 未在 asmx 调用中传输
【发布时间】:2011-10-27 15:53:31
【问题描述】:

我遇到了(浏览器)cookie 问题。

我有一个 Sharepoint 页面 (http://myServer:24628/sites/myApp/myDocumentLibrary/test.aspx)。当请求页面时,我可以在请求标头(使用 firebug)中看到有一个 ASP.NET_SessionId cookie。

请求头:

Host: myServer:24628
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Cookie: ASP.NET_SessionId=2vhaxii0hxqeazii2sgw3q55; WSS_KeepSessionAuthenticated=24628
If-Modified-Since: Thu, 27 Oct 2011 15:41:15 GMT
Cache-Control: max-age=0

响应头:

Cache-Control: private, max-age=0
Content-Length: 210604
Content-Type: text/html; charset=utf-8
Expires: Wed, 12 Oct 2011 15:41:24 GMT
Last-Modified: Thu, 27 Oct 2011 15:41:24 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 12.0.0.6421
X-AspNet-Version: 2.0.50727
Set-Cookie: WSS_KeepSessionAuthenticated=24628; path=/
http%3A%2F%2FmyServer%3A24628%2Fsites%2FmyApp%2FDiscovery=WorkspaceSiteName=UG9ydGFs&WorkspaceSiteUrl=aHR0cDovL3dlYmFwcDAxOjI0NjI4L3NpdGVzL251bnRpbw==&WorkspaceSiteTime=MjAxMS0xMC0yN1QxNTo0MTozMQ==; expires=Sat, 26-Nov-2011 16:41:31 GMT; path=/_vti_bin/Discovery.asmx
Date: Thu, 27 Oct 2011 15:41:31 GMT

页面加载后,我发出一个 asmx 请求(POST):

请求头:

Host    myServer:24628
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept  text/javascript, text/html, application/xml, text/xml, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection  keep-alive
X-Requested-With    XMLHttpRequest
X-Prototype-Version 1.7
Content-Type    application/json; charset=UTF-8
Referer http://myServer:24628/sites/myApp/myDocumentLibrary/test.aspx
Content-Length  42
Cookie  WSS_KeepSessionAuthenticated=24628

就在调用 asmx 之前,我提醒了 'ASP.NET_SessionId' cookie 的值。它就在那里,它的价值是正确的。

在 notify.asmx 调用中,我需要检索 cookie 值才能运行一些逻辑。这显然失败了。
这里发生了什么?

哦,是的,

手动。

【问题讨论】:

  • @jadarnel27 在我脾气暴躁 6 小时后,你将能够在我脸上露出笑容.. thx
  • @jadarnel27 - 哈!我打算发布同样的!我以前被打败过回答,但不是 cookie Monster cmets!
  • @Curt 好主意! @TweeZz 不客气 =)
  • 调用的 javascript 从哪里加载?它是来自“myserver:24628”还是其他域?见stackoverflow.com/questions/2870371/…

标签: javascript asp.net sharepoint asmx


【解决方案1】:

您的 cookie 未发送,因为两个请求的 Host 字段不同:

主机:webapp01:24628

主机 myServer:24628

【讨论】:

  • 那只是因为我在发帖之前忘记手动更改“webapp01”.. 我的错,sry
【解决方案2】:

javascript 确实是从不同的位置加载的。正如 Chris Lively 在对我的问题的评论中所建议的那样。

【讨论】:

    【解决方案3】:

    覆盖所有基地,你有[WebMethod(EnableSession = true)]吗?

    这是否只发生在 IE 中?只在 IE 上看到过这个,必须添加一个 P3P 标头条目,但这是用于跨域 SSO 解决方案。

    【讨论】:

    • 为什么这必须对 WebMethod 属性做任何事情?似乎它的浏览器没有传输 cookie..
    猜你喜欢
    • 1970-01-01
    • 2017-02-03
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    相关资源
    最近更新 更多