How to apply long polling method in ASP.NET MVC?

I know a lot about polling methods, but I can not find anything about how to apply this technique in asp.net mvc. There are so many articles and documentation, but most of them are about php and ajax.

I want to use this technique with my project in two places, one of which is a system of tweets such as twitter, and the other is a chat system. I am curious what is the best way to apply this technique in MVC? Should I use SignalR? This is the best variant?

If you can give me a sample or documentation, it will be great, thanks!

+7
c # asp.net-mvc asp.net-mvc-4 long-polling signalr
source share
3 answers

SignalR is definitely suitable if you want to move data from server to client. I tried to do this using a less well maintained and developed library, and I got it to work, but from what I saw in the SignalR examples, it was much simpler than what I did. Start reading documents and sample code on asp.net relatively confidently.

Here is an article on Code Project that shows you how little code you need to achieve clicking on the server for the client.

http://www.codeproject.com/Articles/524066/SignalR-Simple-Chat-Application-in-Csharp

This is due to the fact that all the heavy lifting for establishing a connection is performed using the SignalR API on the server in .Net and on the client in JavaScript.

+9
source share

What is the "best" solution, for discussion, and this forum is not about that.

If what you want to do is real peer-to-peer communication, SignalR does not do this - it is designed to transfer data from the server to the client and make remote procedure calls (RPC) from the server to the client.

If you want this n-way connection through the server as a central hub, then SignalR is definitely the way to go. It is a proven technology and is fully supported by Microsoft.

Microsoft has published a tutorial on SignalR 2.0 ( http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-getting-started-with-signalr-20 ) that implements the chat application.

+4
source share

If you need an easy way to use SignalR for event-based communications, you can check out my library built on top of SignalR.

Here you can see how to configure it.

https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/wiki

You can also download a demo to check it out and learn how to do it.

https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/tree/master/SignalR.EventAggregatorProxy.Demo.MVC4

+2
source share

All Articles