1 First this demo is for NET version is 4.5 SignalR get 2.2 of
2 Create a new MVC project
3 Nuget Search SignalR installation of an item
4 Create a new hub class
To modify a newly created class
[Hubname ("demo")] Public class Chathub:hub { publicvoid Send (stringstring message) { // Call the Addnewmessagetopage method to update clients. Clients.All.addNewMessageToPage (name, message); } }
5 Startup modification
Public void Configuration (Iappbuilder app) { //Configureauth (APP); app. MAPSIGNALR (); }
6 in the Home/index
<Divclass= "Container"> <inputtype= "text"ID= "message" /> <inputtype= "button"TabIndex= "1"ID= "SendMessage"value= "Send" /> <inputtype= "hidden"ID= "DisplayName" /> <ulID= "discussion"></ul></Div>@section Scripts {<!--Script references. - <!--The JQuery Library is required and was referenced by default in _layout.cshtml. - <!--Reference the SignalR library. - @*<Scriptsrc= "~/scripts/jquery.signalr-1.0.1.js"></Script>*@ <Scriptsrc= "~/scripts/jquery-1.10.2.js"></Script> <Scriptsrc= "~/scripts/jquery.signalr-2.2.0.js"></Script> <Scriptsrc= "~/signalr/hubs"></Script> <!--Reference the autogenerated SignalR hub script. - <!--SignalR script to update the chat page and send messages. - <Script> $(function () { //Reference The auto-generated proxy for the hub. varChat=$.connection.demo; //Create a function, the hub can call back to display messages.Chat.client.addNewMessageToPage= function(name, message) {//ADD the message to the page. $('#discussion'). Append ('<li><strong>' +HtmlEncode (name)+ '</strong>:' +htmlEncode (message)+ '</li>'); }; //Get the user name and store it to prepend to messages. $('#displayname'). Val (Prompt ('Enter your name:', "')); //Set initial focus to message input box. $('#message'). focus (); //Start the connection.$.connection.hub.start (). Done (function () { $('#sendmessage'). Click (function () { //Call the Send method on the hub.Chat.server.send ($ ('#displayname'). Val (), $ ('#message'). Val ()); //Clear text box and reset focus for next comment. $('#message'). Val ("'). focus (); }); }); }); //This optional function html-encodes messages for display in the page. functionHtmlEncode (value) {varEncodedvalue= $('<div/>'). Text (value). html (); returnEncodedvalue; } </Script>}
This is the website demo is the display interface nothing to say
Also attached official website download Zip All the powerful features have!!
More powerful demo on ASP. SignalR website
The Project Demo
Download
Chat Demo SignalR