Signalr javascript客户端错误:未生成动态文件 [英] Signalr javascript client error: dynamic file not generated

查看:198
本文介绍了Signalr javascript客户端错误:未生成动态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是包含signalR的运行时项目的屏幕截图。



https://i.stack.imgur.com/hzzEo.png [ ^ ]



没有生成集线器文件。我得到了最常见的javascript错误,也显示在图片中。

请就此提出建议。代码是来自microsoft docs的示例代码。 教程:SignalR 2入门| Microsoft Docs [ ^ ]



我尝试过:



我搜索并找到了许多解决方案,但似乎没有任何效果。比如更改参考src等。

以下是我引用脚本文件的方法。



 < span class =code-leadattribute>< script     src   =  Scripts / jquery-3.3.1.min.js >  < /   script  >  

<! - 参考SignalR库。 - >
< script src = Scripts / jquery.signalR-2.2.2.min.js > < / script >
<! - 引用自动生成的SignalR集线器脚本。 - >
< script src =' <%:ResolveClientUrl( 〜/ signalr / hubs%> ' > < / script >

解决方案

终于得到了答案。我正在尝试上网的所有可能的事情,然后有一件事情有效。这就是这一行[HubName(myHub)] ..之前我的名字是[HubName(MyHub)],所以错误。



 [HubName(  myHub)] 

public class MyHub:Hub
{

public void 发​​送( string name, string message)
{
// 调用broadcastMessage方法来更新客户端。
Clients.All.broadcastMessage(name,message);
}



您需要定义与javascript中使用的HubName相同的内容,以便在获取客户端时不会产生任何混淆。



  var  chat = 


.connection.myHub;


Here is the screenshot of runtime project that contains signalR.

https://i.stack.imgur.com/hzzEo.png[^]

There is no hubs file generated. I am getting the most common javascript error That is also shown in picture.
Please advice something on this. The code is the sample code from microsoft docs. Tutorial: Getting Started with SignalR 2 | Microsoft Docs[^]

What I have tried:

I searched and found many solutions but nothing seems to work. like changing reference src and etc.
Here is how I am referencing the script files.

<script src="Scripts/jquery-3.3.1.min.js"></script>

    <!--Reference the SignalR library. -->
    <script src="Scripts/jquery.signalR-2.2.2.min.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script>

解决方案

Finally got the answer. I was trying every possible thing I got on internet and then one thing worked. and that was in this line [HubName("myHub")].. I had this name as [HubName("MyHub")] before and so the error.

[HubName("myHub")]

public class MyHub : Hub
{
  
    public void Send(string name, string message)
    {
        // Call the broadcastMessage method to update clients.
        Clients.All.broadcastMessage(name, message);
    }


You need to define HubName same as you used in javascript so that there wont be any confusion in getting client.

var chat =


.connection.myHub;


这篇关于Signalr javascript客户端错误:未生成动态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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