简体   繁体   English

SignalR和ASP.NET核心页面未加载

[英]SignalR and ASP.NET core page not loading

I am trying to set up signalR so that I can send data from my server to javascript to render some graphs. 我正在尝试设置signalR,以便可以将服务器中的数据发送到javascript以呈现一些图形。

I added the required items to Startup.cs (removed all the irrelevant things): 我将所需的项目添加到Startup.cs中(删除了所有不相关的内容):

using MyProject.Hubs

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{    
    services.AddSignalR();    
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseSignalR(routes =>
    {
         routes.MapHub<GraphHub>("/test");
    });

    app.UseMvc();

}

In Hubs.cs 在Hubs.cs中

using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;

namespace MyProject.Hubs
{
     public class GraphHub : Hub
     {
        public async Task SendData(int[] data)
        {
            await Clients.All.SendAsync("sendGraphData", data);
        }
     }
 }

However in my Index.cshtml.cs 但是在我的Index.cshtml.cs中

public IndexModel(MyProject context)
{
    _context = context;
}

public async Task OnGetAsync()
{

   IList<Cats> cat = await _context.Ticket.Where(x => x.Color = "Black").ToListAsync();


   int[] TestData = new int[] {65, 59, 80, 81, 56, 55, 40};

   var hubConnection = new HubConnectionBuilder().WithUrl("http://localhost:44307/test").Build();

   await hubConnection.StartAsync();

   await hubConnection.InvokeAsync("SendData", TestData);

   await hubConnection.DisposeAsync();      
}

Currently the page just gives me a blank screen on await hubConnection.StartAsync(); 当前页面仅在await hubConnection.StartAsync();给我一个空白屏幕await hubConnection.StartAsync(); and I am not sure how to debug it. 而且我不确定如何调试它。 Am I missing a step? 我错过了一步吗?

重新启动我的IDE-现已全部修复≧☉_☉≦

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

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