简体   繁体   English

Asp.Net Core中的SignalR配置

[英]SignalR configuration in Asp.Net Core

I have a problem to find how to configure values as ConnectionTimeout , DisconnectionTimeout in Asp.Net Core with SignalR. 我在查找如何使用SignalR在Asp.Net Core中将值配置为ConnectionTimeoutDisconnectionTimeout时遇到问题。 In MVC you were using Global.asax file and there configuration were placed like this: 在MVC中,您使用的是Global.asax文件,并按以下方式放置配置:

using System;
using Microsoft.AspNet.SignalR;

namespace Wozkowi
{
    public class Global : System.Web.HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Make connections wait 50s maximum for any response. After
            // 50s are up, trigger a timeout command and make the client reconnect.
            GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(20);
            GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(5);
        }
    }
}

But in Asp.Net Core Global.asax don't exist anymore and as I understand configuration should be placed in Startup.cs . 但是在Asp.Net Core Global.asax已经不存在了,据我了解,配置应该放在Startup.cs But main problem is GlobalHost in Microsoft.AspNetCore.SingalR it's undefined. 但是主要问题是Microsoft.AspNetCore.SingalR中的GlobalHost尚未定义。 So how I should add configuration? 那么我应该如何添加配置?

Edit: 编辑:

I'm using Microsoft.AspNetCore.SignalR v.1.0.0-rc1-final. 我正在使用Microsoft.AspNetCore.SignalR v.1.0.0-rc1-final。 So during services.AddSignalR() I can pass object: 因此,在services.AddSignalR()期间,我可以传递对象:

public class HubOptions
    {
        public HubOptions();

        public TimeSpan? HandshakeTimeout { get; set; }
        public TimeSpan? KeepAliveInterval { get; set; }
        public IList<string> SupportedProtocols { get; set; }
        public bool? EnableDetailedErrors { get; set; }
    }

But there still is no option to set DisconnectionTimeout, also during api.UseSignalR() this options object can be passed: 但是仍然没有设置DisconnectionTimeout的选项,在api.UseSignalR()期间也可以传递此选项对象:

public class HttpConnectionOptions
    {
        public HttpConnectionOptions();

        public IList<IAuthorizeData> AuthorizationData { get; }
        public TransportType Transports { get; set; }
        public WebSocketOptions WebSockets { get; }
        public LongPollingOptions LongPolling { get; }
        public long TransportMaxBufferSize { get; set; }
        public long ApplicationMaxBufferSize { get; set; }
    }

But there is still no desired option even in LongPollingOptions object. 但是,即使在LongPollingOptions对象中,仍然没有所需的选项。 I'm missing something? 我想念什么吗?

In Startup.cs look for ConfigureServices method, there you need to add services.AddSignalR() In Configure method configure routes. Startup.cs寻找ConfigureServices方法,您需要在其中添加services.AddSignalR() Startup.cs services.AddSignalR()Configure方法中配置路由。

you can find more info in below msdn link https://docs.microsoft.com/en-us/aspnet/core/signalr/get-started?view=aspnetcore-2.1&tabs=visual-studio 您可以在下面的msdn链接https://docs.microsoft.com/zh-cn/aspnet/core/signalr/get-started?view=aspnetcore-2.1&tabs=visual-studio中找到更多信息

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

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