SIGNALR Series Tutorial: Using SIGNALR in MVC

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.