Monday, July 13, 2020
Beetle Blog
Setting Up SignalR With WebMatrix and WebPages
By: douglas - - 4/14/2013 12:58:34 AM

Following this tutorial:
WebMatrix 2 or 3 (This will also work with 2010, 2012 using the WebPages framework)
Open WebMatrix
Create a new WebPages site.
Using NuGet install the Microsoft ASP.NET SignalR package: Microsoft.AspNet.SignalR
If you are installing from scratch make sure to install the entire package which is exactly Microsoft.AspNet.SignalR, not just the Core or other libraries.
It will install a bunch of JavaScript files and place the SignalR libraries (dlls) in your Bin folder.
Create an App_Code folder.
Create a C# class called ChatHub.cs in the folder.
Replace the contents with the following code:
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRChat
    public class ChatHub : Hub
        public void Send(string name, string message)
            // Call the broadcastMessage method to update clients.
            Clients.All.broadcastMessage(name, message);
Create an _AppStart.cshtml at the root of your site.
Add the following code to _AppStart.cshtml:
@using System.Web.Routing;
@using Microsoft.AspNet.SignalR;
    // Register the default hubs route: ~/signalr/hubs
Add a new HTML page to your site.  For example: chat.html
Replace the contents with the html from the tutorial.
Take a look at the references to your .js libraries and make sure that they match what you have in the /Scripts directory. If not update the references.
If the jQuery you have is older than the one referenced then update your jQuery libraries to at least the one referenced.
Now run the site and go to your chat.html page.  You should get prompted to enter your name and then be able to submit messages to the app.
Open additional tabs or browser windows, browse to the same page and you should be able to see messages typed in other windows get sent to all other open windows.

Last Modified: 4/14/2013 1:19:55 AM

Beetle Blog v0.2.2

Copyright © 1997 - 2020 All rights reserved.