我正在尝试在 Visual Studio 2012 中构建 SignalR 应用程序。我的问题是它在 Visual Studio 调试下运行良好(在 Windows 7 上使用 Visual Studio 2012),但是当我尝试在 Windows Server 2012 上的 IIS 8 上部署应用程序时,该应用程序仅显示 index.html 页面。
我决定尝试缩小问题是在我的代码中还是在 SignalR 中。我编译了 http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr 中显示的 SignalR 教程.这在 Visual Studio 下工作正常,但再一次,除了在 IIS 下显示静态页面外,不会做任何事情。
我尝试了这里列出的一些方法:Signalr/Hub not loading in IIS 7 but working correctly in Visual Studio ,但它们似乎都不起作用。
最佳答案
假设你真的想看 index.html
(即您的问题不是“显示的是空的 index.html 而不是我的聊天页面 chat.html”),那么听起来当您在聊天页面中输入内容时,它不会在其他浏览器窗口中显示为聊天已连接到聊天。
我会尝试一些基本的测试。我将假设:
Microsoft.AspNet.SignalR.Core.dll
、 Microsoft.AspNet.SignalR.Owin.dll
、 Microsoft.AspNet.SignalR.SystemWeb.dll
和其他)。 我会尝试以下测试:
yourdomainnamehere.com/index.html
(如果您已经在那里,则重新加载它)index.html
signalr/hubs
signalr/negotiate
(带查询字符串)signalr/connect
(带查询字符串)所以:
Application_Start
的第一行:protected void Application_Start(object sender, EventArgs e)
{
// Register the default hubs route: ~/signalr/hubs
RouteTable.Routes.MapHubs();
}
$.connection.hub.start()
被调用的代码。 好的,这有效,现在呢?
现在你需要开启 client side logging on 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 端点网站,创建一个新页面:
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。如果没有,那么有两种选择:yourdomainnamehere.com
如果您认为另一个站点可能正在使用主机 header ,那么您可以使用 powershell 在 Win Server 2102 上轻松检查:
Import-Module WebAdministration
Get-WebBinding |? bindingInformation -match .*mydomainname.com.* | ft protocol, bindingInformation, ItemXPath -AutoSize
站点名称和 id 显示在结果列
ItemXPath
下
关于iis - SignalR 应用程序在 IIS 下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16900536/