c# - SignalR 卡住所有后续的 http 请求

标签 c# asp.net .net iis signalr

我正在尝试在我的 Web 应用程序中使用 SignalR,它托管在 IIS 7.5 上。

我正在使用 Windows 7 X64(没有 SP1)和带有 SignalR v2.0.3.0 的 .Net 4.5。

如果我从 IIS Express 运行 Web 应用程序,它工作正常,没有任何挂断,但一旦我从 IIS 7.5 运行它,它就会挂断我的应用程序。我确认如果我禁用这段代码:

 $.connection.hub.start().done(function () {

 });

一切正常。以下是显示集线器启动后所有请求进入无限期阻塞状态的屏幕截图。即使是集线器也需要大约 8-9 秒才能做出响应,但即使在那之后,如果我请求一个简单的 JPG,我也什么也得不到,并且会进入无限期的阻止状态。

enter image description here

这是应用程序池的屏幕截图。我在集成模式下运行。

enter image description here

这是 Hub 类:

 public class AppHub : Hub
    {
        public override Task OnConnected()
        {
            if (Context.User != null)
            {
                var email = Context.User.Identity.Name;
                if (!string.IsNullOrEmpty(email))
                {
                    UserRepository userRepository = new UserRepository();
                    userRepository.DoSomething(email, Context.ConnectionId);
                }
            }

            return base.OnConnected();
        }

        public override Task OnDisconnected()
        {
            if (Context.User != null)
            {
                var email = Context.User.Identity.Name;
                if (!string.IsNullOrEmpty(email))
                {
                    UserRepository userRepository = new UserRepository();
                    userRepository.DoSomething1(email, Context.ConnectionId);
                }
            }

            return base.OnDisconnected();
        }
    }

最佳答案

文档指出你应该在你的开发机器上使用 IIS express,因为并发请求的数量有限制

When SignalR is hosted in IIS, the following versions are supported. Note that if a client operating system is used, such as for development (Windows 8 or Windows 7), full versions of IIS or Cassini should not be used, since there will be a limit of 10 simultaneous connections imposed, which will be reached very quickly since connections are transient, frequently re-established, and are not disposed immediately upon no longer being used. IIS Express should be used on client operating system

Windows 10 也是如此。

取自此处的 SignalR 文档: http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/supported-platforms

关于c# - SignalR 卡住所有后续的 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24276762/

相关文章:

c# - 有没有办法读取发送到扬声器的当前音量?

c# - 当 RegisterEventBus "No service for type Autofac.ILifetimeScope' 已注册时。

c# - 如何删除危险字符(即脚本标签)?

c# - 在 Azure Key Vault 中创建新 key 和 secret

c# - Regex.IsMatch() 无法识别转义序列?

c# - 检测图像中的椭圆图案

javascript - 使用 JQuery 通过单击不同表格中的按钮更改表格行背景颜色

c# - 使用 iTextSharp 创建 Pdf 时将图像水印添加到 Pdf

.net - 过滤 LoadWith 结果

c# - 什么是好的、免费的 C# 单元测试覆盖工具?