SignalR applications do not work under IIS
Asked Answered
D

2

5

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.

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.

Damondamour answered 3/6, 2013 at 15:37 Comment(3)
Are you getting any errors in the console? Turn on logging ($.connection.hub.logging = true).Tristatristam
Is your chat page called index.html? Or is your chat page called something different and index.html is just the default IIS page for a new website?Remde
any final solution with full source code ?Jumbuck
R
26

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 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).

I would try the following tests:

  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. Your page index.html
    2. The javascript files for jQuery, jQuery.signalR being downloaded
  4. It should also show, crucially, the following connections with a 200 return status:
    1. signalr/hubs
    2. signalr/negotiate (with a query string)
  5. And it should show an ongoing connection to
    1. signalr/connect (with a query string)

So:

  • 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)
    {
        // Register the default hubs route: ~/signalr/hubs
        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.

Ok, that works, now what?

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'. 

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

Using your signalr endpoint website, create a new page:

  • 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();

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:

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

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

Remde answered 3/6, 2013 at 20:34 Comment(5)
i have this problem too, i tested your suggested steps. all of them are OK but when i send a message, the last line of SignalR log SignalR: Triggering client hub event... doesn't show up. i don't know what's wrong!Tumefacient
I solved the problem. that was because of my mistake on server side logic.Tumefacient
@AmirOveisi can you elaborate on what the mistake was on your server side logic? I'm having a similar problem and have not been able to figure out what the cause is despite checking everything on the answer above.Snodgrass
@Snodgrass : as far as i remember, that was my mistake on choosing proper clients to update them through Hub.Tumefacient
Thanks this is a fab checklist. In my case there were couple problems. First being JS files not served due to non existing signalR min file and secondly entries required in application manifest file for signal connections.Brogue
R
1

I had the same issue. Sorted it by setting the Application Pool to be ASP.NET v4.0 (v4.0).

I also had to use Chrome and not IE for the demo app to work properly.

Rosariorosarium answered 5/3, 2014 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.