Del via


Hosting a SignalR application on Windows 2008r2 and IIS 7.5

ASP.NET SignalR is Microsoft's new library for adding real-time functionality to applications.   You can host ASP.NET applications with SignalR on Windows Server 2012 and IIS 8 (this setup provides full HTML 5 WebSocket API support for real-time functionality), or you can host on previous versions of Windows Server and IIS.  Previous server versions do not offer websockets support, instead they use fallback transport mechanisms such as forever frames, server-sent events, and Ajax long polling.  For more information, see SignalR Transports.  Because previous server versions use fallback transport mechanisms, hosting on a previous server platform requires a few extra steps to get your SignalR application working in all browsers. 

This posts pulls together several related steps that it takes to get a SignalR application working on a common previous-version hosting scenario:   Windows 2008r2 and IIS 7.5.  You can see a listing of these and other steps for working with SignalR applications on the SignalR Wiki FAQ page.  The application sample used to test the steps in this post is from the tutorial Getting Started with SignalR.  Instead of building the sample on .NET Framework 4.5 (as in the tutorial), I built it on .NET Framework 4, a common hosting scenario on IIS 7.5.

Here's a summary of the required setup steps to host on Windows 2008r2 with IIS 7.5:

  1. Update the SignalR application's web.config file to enable "run all managed modules for all requests" (for short, this is the RAMMFAR setting). 
  2. Update the web page that uses SignalR to communicate with the server:
    1. Add a reference to the json2.js library. 
    2. Add a <meta> tag that forces the content to display in a recent browser mode.
  3. Set up a Windows Server 2008r2 with IIS 7.5 as follows:
    1. Install the .NET Framework version that your SignalR application requires.
    2. Create a site and associate it with the appropriate application pool. 

 

Update the Signalr Application's Web.config File

In your SignalR application's web.config file, add the RAMMFAR setting to enable running all managed modules for all requests. This setting was required to get the SignalR sample application running in on Windows 2008r2 and IIS 7.5 in all browsers. 

<system.webServer>
   <modules runAllManagedModulesForAllRequests="true">
   </modules>
</system.webServer> 

 

Update the Web Page that Uses SignalR

In the application web page that uses SignalR to communicate with the server, add the following code.

  • Add a reference to the json2.js JSON parser library.  This script provides a JSON parser for previous browser versions that don't have it. You can add the script in one of two ways:

<script src="scripts/json2.js"></script>

    • Or as an alternative, reference json2.js on a CDN:  

<script src="https://cdnjs.cloudflare.com/ajax/libs/json2/20121008/json2.js"></script>

  • Add the following <meta> tag in the head section of the page.  This tag, specifically the IE=edge value,  forces Internet Explorer to display content in the most recent version available, rather than earlier modes (such as IE7) which prevent SignalR code from working.

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

 

Set up Windows Server 2008r2 and IIS 7.5

 As noted, I built the sample SignalR application from the Getting Started with SignalR tutorial on .NET 4.  This is a common hosting scenario on Windows 2008r2 and IIS 7.5.   The server was a new default default installation of Windows Server 2008r2 and IIS 7.5.

  • Install the required .NET Framework version.  In this case I installed .NET Framework 4.
  • Create a new site in IIS Manager, and associate the site with an application pool.  Use integrated mode application pools, classic mode is not supported for SignalR.  For this application I used the ASP.NET v4.0 application pool. 

 

After following the above setup steps, I was able to deploy the .NET Framework 4-based version of the Getting Started with SignalR sample to the server, and it worked perfectly in IE (versions 8, 9, and 10), Chrome, and Firefox even though it was using fallback transport methods (forever frames in IE, and server-sent events in the other browsers).   The interesting thing for SignalR developers is that apart from the above steps, I didn't have to change a single line of the SignalR code anywhere in the application to make this work.

This is a simple case but shows that SignalR really does support "automatic fallback" to earlier transport mechanisms when websockets support is not available on the server.

Comments

  • Anonymous
    March 29, 2013
    Web definitions Windows Server is a brand name for server operating systems released by Microsoft Corporation. http://www.veebrij.com/

  • Anonymous
    April 24, 2013
    Thanks!

  • Anonymous
    September 24, 2013
    hello , Signalr/Hub not loading in IIS 7.5 but working correctly in Visual Studio and no scripts load in the  page has a signalr even my masterpage's scripts , and i did everything you saied step by step but doesnt work for me please help me ...

  • Anonymous
    September 24, 2013
    Same here, i'm receiving 404 error.

  • Anonymous
    October 13, 2013
    For me the same problem. Can anyone please correct solution for this.

  • Anonymous
    October 21, 2013
    Basically SignalR is not designed to work with IIS. I guess developer didn't test it with IIS. They did it only on Visual Studio's ASP.NET development server. The fatal problem is, when you deploy SignalR web pages to IIS, a browser tries to get: http://SERVER_NAME/signalr/negotiate?=<key> Instead of expected: http://SERVER_NAME/APPLICATION_NAME/signalr/negotiate?=<key> As a result, IIS has to return HTTP 404 NOT FOUND. Browser doesn't work because it can't get library scripts required to work. If you want SignalR to work with IIS, I think you should configure URL rewrite module to rewrite unexpected URL to expected URL. Or revise all library codes which refers to unexpected URL but it may cause problem with Visual Studio.

  • Anonymous
    October 21, 2013
    > Basically SignalR is not designed to work with IIS. Let me make it clear. SignalR works only if you publish your application to "Site Root" on IIS.

  • Anonymous
    October 31, 2013
    The comment has been removed

  • Anonymous
    December 06, 2013
    As per the Supported Platforms document, you also need to add support for extensionless URLs to your web server if you're using IIS 7.5. Here's that hotfix: support.microsoft.com/.../980368

  • Anonymous
    December 19, 2013
    Many Many Thanks....

  • Anonymous
    January 19, 2014
    Hello, I did it all, but I still can't make this sample work with IIS7.5 (neither on Windows 7.5, nor on Windows Server2008 R2). It works perfectly with IISExpress (v8), but I need to get it working with IIS 7.5 The only thing I did not do is to build it on .NET framework 4, because I am using SignalR v2, which is only compliant with .NET 4.5.

  • I added the <system.webServer> section tu the <configuration> section of my web.config
  • I added a reference to json2.js in my web page (unnecessary, because I am using IE11)
  • I added the meta for old browsers (unnecessary, because I am using IE11)
  • My Application is linked to DefaultAppPool (.NET v4, integrated pipeline) Windows 2008 R2 is up to date, with .NET framework v4.5, which includes the KB980368 hotfix (about ExtensionlessUrlHandler) I did it all, and still $.connection.chatHub remains undefined... Is seems a lot of people found this article useful, can anyone help me to get it working on IIS7.5 with .NET 4.5, or explain how to adapt the sample for .NET 4.0 (if it is the point I missed about the compatibility with IIS7.5) Thank you
  • Anonymous
    January 20, 2014
    I finaly found what was wrong about having SignalR samples working on IIS7.5 SignalR 1.x (.NET framework 4.0) www.asp.net/.../tutorial-getting-started-with-signalr SignalR 2.0 (.NET framework 4.5) www.asp.net/.../tutorial-getting-started-with-signalr-20 The only thing to do if it works with IISExpress but not with IIS7.5 is to remove the "/" at the begining of src attributes in script includes in the html page file: For SignalR 1.1 (.NET frameworj 4.0)    <script src="Scripts/jquery-1.6.4.min.js"></script>    <script src="Scripts/jquery.signalR-1.1.4.min.js"></script>    <script src="signalr/hubs"></script> For SignalR 2.0 (.NET frameworj 4.5)    <script src="Scripts/jquery-1.6.4.min.js"></script>    <script src="Scripts/jquery.signalR-2.0.1.min.js"></script>    <script src="signalr/hubs"></script>

  • Anonymous
    April 14, 2014
    Yes , remove the initial "/" is the solution. Thanks!!

  • Anonymous
    May 01, 2014
    For the Solution gvaiss gave make sure you can access yourserver/signalr/hubs from the browser (or whereever your files are located) before you remove the "/" For me I can't host it on iis 7.5 in win 7 but on 2008r2 it woks fine

  • Anonymous
    November 16, 2014
    I have run MS Visual Studio at www.apponfly.com/.../microsoft-visual-studio-professional-2013 and worked great. I did not need to install anything.

  • Anonymous
    June 08, 2015
    Hi I have solved this problem by

remove '/' from scripts..   <script src="Scripts/jquery-1.6.4.min.js" ></script>    <!--Reference the SignalR library. -->    <script src="Scripts/jquery.signalR-1.1.4.js"></script>    <!--Reference the autogenerated SignalR hub script. -->    <script src="signalr/hubs"></script> 2) Setting Application Pool as Asp.net v4.0 3) Setting this in web.config <system.webServer> <modules runAllManagedModulesForAllRequests="true"> </modules> </system.webServer> Hope it helps :)