简体   繁体   中英

SignalR doesn't work under Visual Studio 2017

I don't know if it's VS2017 or what.. but I have simplest signalR app possible and It doesn't work. Here's my code, maybe you will find something:

I created Empty ASP.NET web application.

Added Startup class:

[assembly: OwinStartup(typeof(Connect4.Server.Startup))]

namespace Test.Server
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

Added ChatHub:

namespace Test.Server
{
    [HubName("chatHub")]
    public class ChatHub : Hub
    {
        public void send(string message)
        {
            Clients.All.addMessage(message);
        }
    }
}

And "Default.aspx" :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test.Server.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Signalr Chat Messenger</title>
    <script src="Scripts/jquery-1.6.4.js"></script>
    <script src="Scripts/jquery.signalR-2.2.2.js"></script>
</head>
<body>
    <form id="form1" runat="server">

    <script type="text/javascript">
        $(function () {

            var IWannaChat = $.connection.chatHub;
            IWannaChat.client.addMessage = function (message) {
                $('#listMessages').append('<li>' + message + '</li>');
            };

            $("#SendMessage").click(function () {
                IWannaChat.server.send($('#txtMessage').val());
            });

            $.connection.hub.start();
        });
    </script>
    <div>
        <input type="text" id="txtMessage" />
        <input type="button" id="SendMessage" value="broadcast" />
        <ul id="listMessages">
        </ul>
    </div>
    </form>
</body>
</html>

Can you see anything wrong? The website is opened with textbox and broadcast button.. but nothing happens after I click it.

BTW. I had to uncheck Enable JavaScript Debugging for ASP.NET (Chrome and IE). (in Tools > Options > Debugging > General > Enable JavaScript Debugging for ASP.NET (Chrome and IE) ), because of this problem

您需要添加hubs脚本

<script type="text/javascript" src="/signalr/hubs"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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