简体   繁体   English

SignalR连接并启动导致404错误

[英]SignalR connect and start cause 404 error

I could not find the specific answer to this when searching so I'm posting my solution here. 我在搜索时找不到具体的答案,所以我在这里发布我的解决方案。

We were working fine with SignalR for a long time, then some users started getting 404 errors on the start and connect calls from AngularJs/jQuery to the server. 我们在SignalR上工作了很长时间,然后一些用户在启动时开始收到404错误,并将来自AngularJs / jQuery的调用连接到服务器。 Negotiate would work fine though and return a 200 code. 谈判可以正常工作,并返回200代码。

It turns out by default the server side (ASP.NET 4.6.1) must impose a limit on the size of a URL and instead of returning a 414 (Request-URI Too Long) like you might expect it must just truncate the URL at a length around 2,083 and still try to process it. 事实证明,服务器端(ASP.NET 4.6.1)必须对URL的大小施加限制,而不是像您预期的那样返回414(Request-URI Too Long),它必须截断URL大约2,083的长度,仍然试图处理它。 I'm assuming the 404 is the SignalR hub responding because now the truncated string has query string parameters that don't match what is expected. 我假设404是SignalR集线器响应,因为现在截断的字符串具有与预期不匹配的查询字符串参数。 We were seeing it because we were passing a couple custom values and the security access token via query string parameters which increased the size. 我们看到它是因为我们通过查询字符串参数传递了一些自定义值和安全访问令牌,这增加了大小。 The access token was passed via query string because we wanted to use websockets and headers don't exist for websockets. 访问令牌是通过查询字符串传递的,因为我们想使用websockets并且不存在websockets的头文件。 As you add more attributes and roles to your token it will grow which is what put us over the default size limit. 当您向令牌添加更多属性和角色时,它会增长,这使我们超出默认大小限制。

The fix is easy. 修复很容易。 Just update your server web.config to allow longer URLs. 只需更新您的服务器web.config以允许更长的URL。

 <system.web> <httpRuntime targetFramework="4.5" maxRequestLength="30000000" maxUrlLength="40960" maxQueryStringLength="2097151" /> </system.web> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="30000000" maxUrl="40960" maxQueryString="2097151" /> </requestFiltering> </security> </system.webServer> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM