Sunday, February 7, 2016

SignalR in web forms?

Sure! It's not too hard. Just install these NuGet packages:

  1. Microsoft ASP.Net SignalR System.Web
  2. Microsoft ASP.Net SignalR JavaScript Client

 
 

These script tags need to adorn your .aspx markup where you want the magic to happen:

<script src="Scripts/jquery-1.6.4.js"></script>
<script src="Scripts/jquery.signalR-2.2.0.js"></script>

 
 

Beyond that it is really just like this MVC example. I did hit one painpoint, but it should happen with MVC too honestly. In an IIS application, where \ is not the root of the site but one folder up from that, the setting in the OWIN Startup class should stay the same, but the setting in jQuery where one actually makes the connection needs to be adjusted. At...

var conn = $.connection("/author");

 
 

...one is literally trying to find something at /author and that won't work in an IIS application. Use a full path here as a best practice.

No comments:

Post a Comment