The main contents of this chapter:
1: Add Signair to MVC5
2: What is a hub and how do I create a hub
3: Client calls Hub via Jqery
This article is also a continuation of the "Signair QuickStart" in the chat room example to explain. First we create an MVC Web App through Visual Studio and use the package management console to perform "Install-package Microsoft.AspNet.SignaLR" to install the latest version of SignaLR.
In the solution we create a new folder named "Hubs", then create a new hub within the folder and name the class ChatHub.cs.
Using Microsoft.aspnet.signalr;namespace mvc_signair.hubs{public class Chathub:hub {public void Hello ( { Clients.All.welcome ("Hello everyone, welcome to read this article"); } public void Send (string name, String message) { Clients.All.addNewMessageToPage (name,message);}} }
We create a new Owin startup class that registers the SIGNALR hub route in the Configuration method
Using microsoft.owin;using Owin; [Assembly:owinstartup (typeof (Mvc_signair.startup))]namespace mvc_signair{public class Startup { public void Configuration (Iappbuilder app) { app. MAPSIGNALR ();}}}
We create a new home controller, add an action named "Chat" and add a view with no model
@{viewbag.title = "Chat";} Run the project to see the effect
SIGNALR Series Tutorial: Using SIGNALR in MVC