Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR and MVC bundle

Tags:

I'm trying to use SignalR with MVC bundle, but having problem finding out how to include the /signalr/hubs script into the bundle. For now I have to insert the path in between jquery.signalR and my code. That will result in three javascript file requests.

Is there any way to include /signalr/hubs into my mvc bundle?

like image 641
thenail Avatar asked Jul 19 '12 07:07

thenail


People also ask

How does SignalR hub work?

What is a SignalR hub. The SignalR Hubs API enables you to call methods on connected clients from the server. In the server code, you define methods that are called by client. In the client code, you define methods that are called from the server.

What is SignalR C#?

SignalR is nothing but an Asynch Library which can be used to develop web applications and those applications provide some services which runs asynchronously. In other terms, SignalR is a library that can be used to create Real-Time applications.

What is SignalR in ASP NET MVC?

In webgrid of Asp.Net MVC when we perform Crud operations the signalR shows the task the record using the Id entered , updated or deleted. It just shows like system task manager. There are two sides -- One is Server Side and another one is Client Side.


3 Answers

A bit late, but here is my contribution:
Create a javascript file with the following contents:

(function ($) {
    $.ajax({
        url: "/signalr/hubs",
        dataType: "script",
        async: false
    });
}(jQuery));

Then add the file to the bundles collection.
This will load the "/signalr/hubs" code for you.

like image 116
KTW Avatar answered Oct 19 '22 07:10

KTW


The default /signalr/hubs script is generated dynamically by the runtime on the first request and then cached.

You can use hubify.exe (see http://weblogs.asp.net/davidfowler/archive/2012/06/10/signalr-0-5-1-released.aspx for details) to pre-generate the file yourself, so you can add it into the MVC bundle.

like image 21
Alexander Köplinger Avatar answered Oct 19 '22 09:10

Alexander Köplinger


I know this is an old thread but I would like to add the following for SignalR 2.x. I really wanted to bundle the proxy using SquishIt and by trial and error I managed to come up with the following:

using Microsoft.AspNet.SignalR
using Microsoft.AspNet.SignalR.Hubs

var resolver = new DefaultHubManager(new DefaultDependencyResolver());
var proxy = new DefaultJavaScriptProxyGenerator(resolver, new NullJavaScriptMinifier());
string iCanHazScriptNao = proxy.GenerateProxy("/signalr");
like image 45
Michael Viktor Starberg Avatar answered Oct 19 '22 09:10

Michael Viktor Starberg