Home > ASP.NET, Development > SignalR–Configuring timeout for connections

SignalR–Configuring timeout for connections

Based on the SignalR wiki, in order to make SignalR work with Azure or load balancers, you will need to tune it such that the polling timeout is lesser than the default polling time of 110 seconds.

To do this, the wiki at https://github.com/SignalR/SignalR/wiki/Configuring-SignalR tells you to do the following

ASP.NET Example (Global.asax)

 var config = AspNetHost.DependencyResolver.Resolve<IConfigurationManager>(); 
 config.ReconnectionTimeout = TimeSpan.FromSeconds(25);

 

However if you were to just copy and paste that, you will find that visual studio reports the following 2 errors and wurlies on your code

The name ‘AspNetHost’ does not exist in the current context

and

The type or namespace name ‘IConfigurationManager’ could not be found (are you missing a using directive or an assembly reference?)

 

image

 

Actually what happens is that the wiki actually forgot to mention that you will actually need to import a few namespaces to global.asax.

They are

  1. SignalR.Configuration – Fixes the IConfigurationManager
  2. SignalR.Hosting.AspNet – Fixes AspNetHost
  3. SignalR.Infrastructure – This is where the Resolve extension reside
      So after adding all these, your global.asax will look like

      <%@ Application Language="C#" %>

      <%@ Import Namespace="SignalR.Configuration" %>

      <%@ Import Namespace="SignalR.Hosting.AspNet" %>

      <%@ Import Namespace="SignalR.Infrastructure" %>

      <script runat="server">

          void Application_Start(object sender, EventArgs e)

          {  
              // Code that runs on application startup

              var config = AspNetHost.DependencyResolver.Resolve<IConfigurationManager>();

              config.ReconnectionTimeout = TimeSpan.FromSeconds(25);

          }

      </script>

    Enjoy!

    Advertisements
    Categories: ASP.NET, Development Tags:
    1. March 22, 2012 at 3:37 am

      Thank you for posting this! This had me a bit baffled. I didn’t think to poke around the SignalR library for an extension method. It’s too bad that VS doesn’t discover extension methods and provide a “corrective action suggestion” like it does for “using {namespace}” and other things.

    2. June 19, 2012 at 6:23 pm

      Great to know. Thank you!

    3. July 24, 2012 at 9:51 pm

      Your post is now out of date. The SignalR Wiki has been updated with new code for setting the Timeouts. Thanks for the post though, gave me the link to what I needed!

    1. No trackbacks yet.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: