本文介绍了SignalR应用程序在IIS下无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio 2012中构建一个SignalR应用程序。我的问题是它在Visual Studio调试下运行良好(在Windows 7上使用Visual Studio 2012),但是当我尝试在Windows上的IIS 8上部署应用程序时在Server 2012中,该应用程序只执行index.html页面。

I am trying to build a SignalR application in Visual Studio 2012. My problem is that it works well under Visual Studio debug (using Visual Studio 2012 on Windows 7), but when I try to deploy the app on IIS 8 on Windows Server 2012, the app does nothing more than displaying the index.html page.

我决定尝试缩小问题是在我的代码中还是在SignalR中。我编译了。这在Visual Studio下工作正常,但再一次,除了在IIS下显示静态页面之外,它不会做任何其他事情。

I decided to try to narrow down whether the issue is in my code or in SignalR. I compiled the SignalR tutorial shown at http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr. This works fine under Visual Studio but, once again, does not do anything other than displaying a static page under IIS.

我尝试过这里列出的一些方法:,但它们似乎都不起作用。

I have tried some of the methods listed here: Signalr/Hub not loading in IIS 7 but working correctly in Visual Studio, but none of them seem to work.

推荐答案

假设您确实想要查看 index.html (即您的问题不是一个空的index.html正在显示而不是我的聊天页面chat.html),这听起来就像当你在聊天页面输入内容时,它没有显示为连接到聊天的其他浏览器窗口中的聊天。

Assuming that you actually want to see index.html (i.e. your question is not "an empty index.html is showing instead of my chat page chat.html"), then it sounds like when you enter something into the chat page it is not showing up as a chat in other browser windows who are connected to the chat.

我会尝试一些基本测试。我将假设:

I would try a few basic tests. I am going to assume that:


  • 在服务器上安装和配置ASP.NET(如果没有,请参阅脚注)

  • SignalR库部署到服务器( Microsoft.AspNet.SignalR.Core.dll Microsoft.AspNet。 SignalR.Owin.dll Microsoft.AspNet.SignalR.SystemWeb.dll 和其他人。)

  • ASP.NET is installed and configured on the server (if not then see the footnote)
  • The SignalR libraries are deployed to the server (Microsoft.AspNet.SignalR.Core.dll, Microsoft.AspNet.SignalR.Owin.dll, Microsoft.AspNet.SignalR.SystemWeb.dll and the others).

我会尝试以下测试:


  1. 安装,或使用浏览器开发工具中的网络选项卡(在浏览器中按F12)。

  2. 浏览 yourdomainnamehere.com/index.html (如果您已经在那里,请重新加载)

  3. 网络跟踪应显示200(或可能是304)状态:
  1. Install Fiddler, or use the Network tab in the browser dev tools (press F12 in your browser).
  2. Browse to yourdomainnamehere.com/index.html (or reload it if you are already there)
  3. The network trace should show 200 (or maybe 304) status for:

  1. 您的页面 index.html

  2. jQuery的javascript文件,jQuery.signalR正在下载


  • 它还应显示,至关重要的是,以下具有200返回状态的连接:

  • It should also show, crucially, the following connections with a 200 return status:


    1. signalr / hubs

    2. signalr / negotiate (带查询字符串)

    1. signalr/hubs
    2. signalr/negotiate (with a query string)


  • 它应该显示持续连接

  • And it should show an ongoing connection to


    1. signalr / connect (带查询字符串)

    1. signalr/connect (with a query string)


  • 所以:


    • 如果你没有看到上面的3.2,那么你就知道javascript文件没有被提供,所以你需要找出原因(它们在服务器上是/你的html中的路径是否正确)。

    • 如果你看到了,但不是4.1,那么ASP.NET路由有问题。检查您在 Application_Start 中的第一行

    protected void Application_Start(object sender, EventArgs e)
    {
        // Register the default hubs route: ~/signalr/hubs
        RouteTable.Routes.MapHubs();
    }
    


  • 如果你看到了,但不是4.2或5.1那么你的javascript阻止调用 $。connection.hub.start()代码的问题。

    现在你需要打开。在index.html聊天页面中,您可以看到 $。connection.hub.start()。done(function(){行,添加以下内容以便代码读取:

    Now you need to turn on client side logging on signalr. In your index.html chat page, where you see the $.connection.hub.start().done(function () { line, add the following so that the code reads:

        $.connection.hub.logging = true;
        $.connection.hub.start().done(function () {`
    

    再次打开浏览器开发工具,然后切换到控制台选项卡。现在加载页面并发送聊天。查看您收到的错误消息,如果有的话。成功打开页面并发送聊天消息应该生成如下日志:

    Open the browser dev tools again, and switch to the console tab. Now load the page and send a chat. See what error messages you get, if any. Succesfully opening the page and sending a chat message should generate a log such as:

    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



    使用您的信号器终端网站,创建一个新页面:

    Footnote: How to test that ASP.NET is installed and configured on the server

    Using your signalr endpoint website, create a new page:


    • 将其设为aspx Web表单(或mvc表单)并将其命名为 TestAspNet.aspx

    • 进入TestAspNet.aspx,添加标签控件< asp:Label runat =serverID =lblTest>< / asp:Label> ;

    • 进入后面的代码,在 Page_Load 中添加此代码: this .lblTest.Text = DateTime.Now.ToLongTimeString();

    • make this an aspx web form (or an mvc form) and call it TestAspNet.aspx.
    • into the TestAspNet.aspx, add the label control <asp:Label runat="server" ID="lblTest"></asp:Label>
    • into the code behind, add this code in Page_Load: this.lblTest.Text = DateTime.Now.ToLongTimeString();

    现在将其部署到您的Web服务器,并导航至 http://yourdomainnamehere.com/TestAspNet.aspx 。如果这显示当前服务器时间,则您知道ASP.NET已安装在服务器上。如果没有,则有两种选择:

    Now deploy this to your web server, and navigate to http://yourdomainnamehere.com/TestAspNet.aspx. If this shows you the current server time, you know ASP.NET is installed on the server. If not then there are two options:


    • 服务器上的另一个网站使用主机标头 yourdomainnamehere.com

    • 您需要在服务器上安装ASP.NET。要执行此操作,请查看technet文章,以及特别是

    • Another website on the server is using the host header yourdomainnamehere.com
    • You need to install ASP.NET on the server. To do this, review the technet articles "Build an ASP.NET Website on IIS", and particularly "Step 1: Install IIS and ASP.NET Modules"

    如果您认为其他网站可能正在使用主机标头,那么您可以使用PowerShell在Win Server 2102上轻松检查:

    If you think that another site might be using the host header, then you can use powershell to easily check this on Win Server 2102:

    Import-Module WebAdministration
    Get-WebBinding |? bindingInformation -match .*mydomainname.com.* | ft protocol, bindingInformation, ItemXPath -AutoSize
    

    网站名称和ID显示在结果列 ItemXPath

    The site name and id are shown under the result column ItemXPath

    这篇关于SignalR应用程序在IIS下无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-06 16:18