Skip to main content

SignalR Tutorial: Introduction to SignalR in ASP.Net

What is SignalR?

SignalR is open source .Net library managed by David Fowler and Damien Edwards and well supported by Microsoft and now it is part of ASP.Net framework as well. You can see this project on GitHub.

Interaction using SignalR

Key points about SignalR:

·         SignalR is invented by David Fowler and Damien Edwards in August 2011.
·         SignalR is an asynchronous signaling framework to help build real-time, multi-user interactive web applications.
·         Real time means connection and conversation happens in real time, for e.g. chat server.
·         It is built on top of ASP.NET (server side) and a JavaScript library (on the client side) that enables clients (browser) and server (ASP.NET based) components to have a bidirectional conversation.
·         SignalR will use WebSockets when it's available, and gracefully fallback to other technologies when it isn't, while your application code remains the same.
·         WebSocket is a new HTML5 API that enables bi-directional communication between the browser and server and that is exactly what we want to achieve through SignalR.
·         It maintains a persistent connection between client and server and lets the client send multiple messages to the server and the server replies those messages asynchronously.
·         It uses an existing technique called long polling and keeps the connections open between a client and web server.
·         It provides support for connection management, e.g. connect/disconnect events, grouping connections, authorization etc.
·         It also provides a very simple and high-level API for calling JQuery/JavaScript functions in your clients' browsers from server-side ASP.NET code (i.e. server to client RPC).
·         It can be considered as a solution dealing with stateless nature of web by making the web appear to behave in a stateful way.

Why do we need SignalR?

This question run in our mind whenever we learn any new technology and SignalR is not an exception in this case J

·         It is an open-source .NET library for building web applications that require real-time data updates or live user interaction.
·         Most common examples where SignalR can be used are news tickers, sport site, chat clients, stock or weather updates.
·         Any web application or web page that implements Ajax long polling to retrieve new data, is good candidate for using SignalR.
·         SignalR also enable us to create rich collaborative web applications in ASP.NET, for e.g. real-time gaming.

Prerequisites to create SignalR application: 

To get started with SignalR you will need a few things installed:

·         Visual Studio 2012 Express (or any version of Visual Studio 2012 Professional and up) or Visual Studio 2010 SP1.
·         2012 Express Development Tool.
·         For Visual Studio 2010, install ASP.NET MVC 4.
·         If you don’t have any of required tools then you can check ASP.Net download page and install them.

In next post we’ll use SignalR to create a sample chat application.

Comments

Popular posts from this blog

C#: Merging Excel cells with NPOI HSSFWorkbook

In this post we’ll see how to merge the two or more cell with each other while creating the excel sheet using NPOI . Mentioned below is code to merge multiple cells, in this example we are merging first cell to fifth cell of first row (you can adjust row or cell range by passing particular parameters in CellRangeAddress). //Created new Workbook var hwb = new NPOI.HSSF.UserModel. HSSFWorkbook (); //Create worksheet with name. var sheet = hwb.CreateSheet( "new sheet" ); //Create row and cell. var row = sheet.CreateRow(0); var cell = row.CreateCell(0); ; //Set text inside cell cell.SetCellValue( "This is Merged cell" ); cell.CellStyle.WrapText = true ; //define cell range address // parameters: -> first row to last and first cell to last cell var cra = new NPOI.SS.Util. CellRangeAddress (0, 0, 0, 4); //Add merged region to sheet. sheet.AddMergedRegion(cra); Hope this solution helps you J

Error 405 : ASP.NET Core Web API PUT and DELETE Methods not allowed

Recently, while working with .Net core API I came across the issue of “Error 405 — Methods not Allowed” After some research, I found out that both GET and POST requests working fine but neither PUT nor DELETE requests working. Another thing is that the PUT and DELETE request was also working fine on my local machine but failed when we host on our Azure server. When I explored the issue on the web it led me to the conclusion that WebDAVModule seems to set PUT and DELETE request methods disabled by default and due to that PUT and DELETE throw 405 errors. To make the PUT and DELETE requests work, we need to override the WebDAVModule setting in web.config file by adding the below settings under “ system.webServer ”. < system.webServer >   < modules runAllManagedModulesForAllRequests = " false " >     < remove name = " WebDAVModule " />   </ modules > </ system.webServer > There may be 2 web.config files in y...

How to set Swagger as the default start page for API hosted on the Azure web app?

I created an Asp.Net Core 2.x Web API and configured Swagger on it, below is the code added in Configure method under Startup.cs file, for full swagger configuration, check here //Add swagger configuration app.UseSwagger(); app.UseSwaggerUI(c => {     c.SwaggerEndpoint( "../swagger/v1/swagger.json" , "Test API V1" ); }); On my local machine when I run the API it is automatically redirected to the Swagger page. However, when I hosted this API as an Azure web app it is not redirecting directly to the Swagger and to access the swagger, I had to append /swagger in the URL, for example, https://testapi.azurewebsites.net/swagger/ Solution: Set RoutePrefix to string.Empty under app.UseSwaggerUI like below: app.UseSwaggerUI(c => {     c.SwaggerEndpoint( "../swagger/v1/swagger.json" , "Test API V1" );      c.RoutePrefix = string .Empty; // Set Swagger UI at apps root }); And that’s it, now when you b...