What is this Article all about?
This article attempts to explain the things that you need to know about SignalR and MVC prior to starting to set it up in your MVC projects. Yes I am aware that the new VS2012 and MVC 4 will make it easier for us and install it automatically with the templates and all will be right with the world. Unfortunately, not all of us are starting a project from scratch when using SignalR or aren’t allowed to be on “ the cutting technology edge”. So I wanted to briefly explain SignalR and then let everyone know what the things you should watch out for while setting up your project. It is not a tutorial on using SignalR, I will be doing a separate article for that.
What is SignalR?
- Stock Tickers
- Ticket Queues
- Chat room sites (Jabber website chat hosts with SignalR)
- Credit Card Information
The list can go on, but I digress. So the question becomes, what does all this? A man by the name of David Fowl (https://github.com/davidfowl) created SignalR in his spare time. It has gained traction in the past year and is spreading like wild fire with the help of Microsoft, specifically, Scott Hanselman. He is a speaker / consultant for Microsoft and speaks on SignalR at many of his conferences and sees great promise in the tool. His blog is Here. You will hear me talk about him a lot because I follow his blog quite often as he sees many technologies for what they are. So enough about what SignalR, how does one use it in an MVC project?
Using SignalR in an MVC project
So now you know what SignalR is, how does one use it. Well, the best way to add it to your project is through the NuGet Gallery. If you aren’t already familiar with NuGet, I will be creating a separate blog for how to add it to VS and what it is used for. This blog assumes you have used it before.
Opening Package Manager, at the console prompt type the following:
PM> Install-Package SignalR
1. On the SiteMaster page ( or wherever you are referencing the main JQuery script), make sure you are on the proper JQuery version for the SignalR version being used. Visual Studio adds jquery to the project for you, which is nice, but it happened to be 1.4.4, when it turned out I needed 1.6.4.
2. When using your references to the JQuery signalR scripts (especially the signalR/hubs folder) be sure to use the MVC HTML helper URL.Content(); routine. This allows MVC to decide where you are in relation to the said file instead of you trying to guess every time you use it. Examples of this are:
If you keep these two things in mind, you should have a much easier time implementing your first SignalR and will be on your way to real-time data websites and applications.