并非从客户端发送SignalR cookie [英] SignalR cookies not sent from client

查看:138
本文介绍了并非从客户端发送SignalR cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从客户端发送的cookie,该cookie用作我的MVC Web服务的一部分,但是,现在我已经将集线器集成到此应用程序中,该集线器不会发送该cookie,而mvc应用程序却可以. /p>

现在,在阅读了其他类似的问题(不是很多问题)之后,似乎应该归咎于cookie域,或者未设置路径.

当前,我的系统有2个Web应用程序,即ui和服务.在我的开发环境中,就像这样:

服务 http://localhost:23456/<some route>

UI http://localhost:34567/<some route>

因此,在上面的示例中,ui将向服务发送查询,并在响应上获取授权cookie,该cookie在其他地方使用.

在此示例中,该服务的cookie域是localhost,根据我在其他问题上所读并看到的内容,不需要端口,它将自动允许所有端口.

> HTTP cookie端口是否特定?

SignalR连接请求未发送cookie

在我看来,上面的cookie具有正确的域,并且路径设置为/,因此它应该可以工作.但是,它不会在javascript的请求中发送它们.

我的请求是一个CORS请求,所以我不确定是否有任何怪癖,但所有正常的jquery ajax调用都会使它与cookie一起进入服务器,有什么主意吗?

我的cookie也是httponly,所以不确定这是否有帮助...

==编辑==

试图排除某些问题,已关闭httponly,但仍拒绝将cookie发送到服务器,我还注意到一些未解决的cookie问题,其中提到在某处添加以下代码以使ajax表现出一定的功能方式:

$.ajax({
                xhrFields: {withCredentials: true}
            })

尝试过使用它,但仍然没有运气,所以我没有主意.

解决方案

我提出了一个问题,因为<与CORS和Cookie有关的SignalR 2版beta.

https://github.com/SignalR/SignalR/issues/2318

不过,您可以通过添加以下内容来手动解决此问题:

xhrFields: {withCredentials: true}

对于jquery.signalr-*.js中的所有ajax请求,这将随后通过CORS发送cookie,尽管我不知道这是否会对较旧的浏览器或IE产生不利影响.

I have a cookie which is sent from the client which is used as part of my MVC web service, however now that I have integrated a hub into this application the hub doesnt get sent the cookie, whereas the mvc app does.

Now after reading other similar questions (not that there are many) the cookies domain seems to be to blame, or the path is not set.

Currently my system has 2 web apps, the ui and service. In my dev environment it is like so:

Service http://localhost:23456/<some route>

UI http://localhost:34567/<some route>

So in the above example, the ui will send a query to the service, getting an authorisation cookie on the response, which is used elsewhere.

In this example the cookie domain from the service is localhost, as from what I have read and seen on other questions there is no need for a port, it will automatically just allow all ports.

Are HTTP cookies port specific?

SignalR connection request does not send cookies

So it would appear to me that the cookie above has correct domain, and the path is set to /, so it should work. However it doesn't send them in the request from javascript.

My request is a CORS request so I am not sure if there are any quirks around that but all normal jquery ajax calls make it to the server fine with the cookies, any ideas?

OH also my cookies are httponly as well, not sure if this makes a difference...

== Edit ==

Have tried to rule out some stuff, have turned off httponly and it still refuses to send the cookies to the server, I have also noticed a few outstanding cookie issues which mention adding the following code in somewhere to make ajax behave a certain way:

$.ajax({
                xhrFields: {withCredentials: true}
            })

Tried using that and still no luck, so I am out of ideas.

解决方案

I raised an issue as there is an underlying issue with < version 2 beta of SignalR relating to CORS and cookies.

https://github.com/SignalR/SignalR/issues/2318

However you can manually fix this issue by appending:

xhrFields: {withCredentials: true}

to all ajax requests within the jquery.signalr-*.js, this will then send cookies over CORS, although I do not know if this has any adverse effects on older browsers or IE.

这篇关于并非从客户端发送SignalR cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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