C# 未生成信号器/集线器文件

C# 未生成信号器/集线器文件,c#,webforms,signalr,signalr-hub,C#,Webforms,Signalr,Signalr Hub,我在网上看到了类似的问题,但没有解决办法 我在做网络表单 已安装信号器2.2.2和jQuery 3.3.1 我的剧本 <script src='<%: ResolveClientUrl("/Scripts/jquery-3.3.1.min.js") %>'></script> <script src='<%: ResolveClientUrl("/Scripts/jquery.signalR-2.2.2.min.js") %>'><

我在网上看到了类似的问题,但没有解决办法

我在做网络表单

已安装信号器2.2.2和jQuery 3.3.1

我的剧本

<script src='<%: ResolveClientUrl("/Scripts/jquery-3.3.1.min.js") %>'></script>
<script src='<%: ResolveClientUrl("/Scripts/jquery.signalR-2.2.2.min.js") %>'></script>
<script src="/signalr/hubs"></script>

<script type="text/javascript">
    $(function () {
        // Declare a proxy to reference the hub.
        var alpha = $.connection.alphaHub;
        // Create a function that the hub can call to broadcast messages.
        alpha.client.broadcastMessage = function (message) {
            alert(message);
            //// Html encode display name and message.
            //var encodedName = $('<div />').text(name).html();
            //var encodedMsg = $('<div />').text(message).html();
            //// Add the message to the page.
            //$('#discussion').append('<li><strong>' + encodedName
            //    + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
        };
        // Start the connection.
        $.connection.hub.start().done(function () {
            $('#sendmessage').click(function () {
                // Call the Send method on the hub.
                alpha.server.display($("parameters here"));

            });
        });
    });
</script>
枢纽类

public class AlphaHub : Hub
{
    public void Display(string name, string message)
    {
        Clients.All.broadcastMessage(name, message);
    }
}

我测试了相同的代码。建立了独立的项目,并在那里工作。问题出在我当前的项目中。

您是否尝试在
ConfigureServices
方法中配置
services.AddSignalR()
方法?@T–n我的启动类中没有ConfigureServices()方法。我添加了ConfigureServices(IServiceCollection services)方法,但“services”没有AddSignalR();哦,我看到你在使用
webforms
tag,我以为你在寻找asp.NETMVC版本。对不起。在您的情况下,您可以这样做:@T–n我的代码与您链接的帖子中的代码完全相同。不同之处在于,本文作者的“RouteTable.Routes.MapHubs();”已经过时,我需要使用app.MapSignalR(),其中“app”取自方法参数,类型为IAppBuilder。仍然没有结果抱歉,我不擅长webforms,但您的问题可能与您尝试在
ConfigureServices
方法中配置
services.AddSignalR()
相同?@T–n我的启动类中没有ConfigureServices()方法。我添加了ConfigureServices(IServiceCollection services)方法,但“services”没有AddSignalR();哦,我看到你在使用
webforms
tag,我以为你在寻找asp.NETMVC版本。对不起。在您的情况下,您可以这样做:@T–n我的代码与您链接的帖子中的代码完全相同。不同之处在于,本文作者的“RouteTable.Routes.MapHubs();”已经过时,我需要使用app.MapSignalR(),其中“app”取自方法参数,类型为IAppBuilder。还是没有结果对不起,我不擅长网络表单,但你的麻烦可能和我一样
public class AlphaHub : Hub
{
    public void Display(string name, string message)
    {
        Clients.All.broadcastMessage(name, message);
    }
}