假设您实际上想查看
index.html
(即您的问题不是“空的index.html显示而不是我的聊天页面chat.html”),那么当您在聊天页面输入内容时,似乎其他连接到聊天的浏览器窗口中并没有显示出来。
我建议尝试一些基本测试。我假设:
- ASP.NET已安装并配置在服务器上(如果没有,请参阅脚注)
- SignalR库已部署到服务器上(
Microsoft.AspNet.SignalR.Core.dll
,Microsoft.AspNet.SignalR.Owin.dll
,Microsoft.AspNet.SignalR.SystemWeb.dll
和其他库)。
我会尝试以下测试:
- 安装Fiddler,或使用浏览器开发工具中的网络选项卡(在浏览器中按F12)。
- 浏览到
yourdomainnamehere.com/index.html
(如果您已经在那里,请重新加载)
- 网络跟踪应该显示以下状态为200(或可能为304):
- 您的页面
index.html
- 下载jQuery、jQuery.signalR的javascript文件
- 它还应该显示以下关键连接状态为200:
signalr/hubs
signalr/negotiate
(带查询字符串)
- 它应该显示与以下持续连接:
signalr/connect
(带查询字符串)
因此:
- If you don't see 3.2 above, then you know the javascript files are not being served, so you need to find out why (are they there on the server/is the path correct in your html).
If you see that, but not 4.1 above, then there is a problem with the ASP.NET routing. Check that you have this as the first line in your Application_Start
:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs();
}
If you see that, but not 4.2 or 5.1 then there is a problem with your javascript that is preventing the $.connection.hub.start()
code being called.
好的,现在怎么办?
现在您需要在signalr上打开客户端日志记录。在您的index.html聊天页面中,当您看到$.connection.hub.start().done(function () {
这一行时,请添加以下内容,以使代码读取:
$.connection.hub.logging = true;
$.connection.hub.start().done(function () {`
再次打开浏览器的开发工具,切换到控制台选项卡。现在加载页面并发送聊天消息。查看您是否收到任何错误消息。成功打开页面和发送聊天消息应该会生成以下日志:
LOG: [12:34:56 UTC+0100] SignalR: Negotiating with '/signalr/negotiate'.
LOG: [12:34:56 UTC+0100] SignalR: This browser doesn't support SSE.
LOG: [12:34:56 UTC+0100] SignalR: Binding to iframe's readystatechange event.
LOG: [12:34:56 UTC+0100] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000
LOG: [12:34:56 UTC+0100] SignalR: Triggering client hub event 'broadcastMessage' on hub 'ChatHub'.
注:如何测试服务器上是否已安装和配置ASP.NET
使用您的signalr端点网站,创建一个新页面:
- 将其作为aspx网页表单(或mvc表单)并命名为
TestAspNet.aspx
。
- 在TestAspNet.aspx中添加标签控件:
<asp:Label runat="server" ID="lblTest"></asp:Label>
- 在代码后台中,将以下代码添加到
Page_Load
中:this.lblTest.Text = DateTime.Now.ToLongTimeString();
现在将其部署到您的Web服务器,并导航到http://yourdomainnamehere.com/TestAspNet.aspx
。如果此操作向您显示当前服务器时间,则说明 ASP.NET 已安装在服务器上。否则,有两个选项:
如果您认为可能有另一个站点在使用主机头,则可以在 Win Server 2012 上使用 powershell 轻松检查此问题:
Import-Module WebAdministration
Get-WebBinding |? bindingInformation -match .*mydomainname.com.* | ft protocol, bindingInformation, ItemXPath -AutoSize
网站名称和ID显示在结果列下的ItemXPath
中