0

I am trying to run signalR with DotVVM framework and I have problem with connection to my sample hub.

Here is my js code where I have a problem. $.connection is always undefined so I cant make any connection to my SignalR Hub and thats weird. Is it possible to use SignalR with DotVVM framework?

$(function () {
    var connection = $.connection.testHub();
    var proxy = connection.createHubProxy("testHub");
    connection.start();

    proxy.client.hello = function (message) {
        console.log(message);
   }
})

Scripts registration

<script src="~/AdminTemplate/Components/jquery/dist/jquery.min.js"></script>
<script src="~/AdminTemplate/Scripts/jquery.signalR-2.2.2.js"></script>
<%--<script src="~/signalr/hubs"></script>--%>
<script src="~/Hubs/Scripts/test.js"></script>

Here is my simple hub which only sends some string

public class TestHub : Hub
{
    public void Hello()
    {
        var message = "test";
        Clients.All.hello(message);
    }
}

Startup class

public void Configuration(IAppBuilder app)
{
    var compositionRootFactory = new CompositionRootFactory();
    var container = compositionRootFactory.CreateContainer();

    var serviceInitializer = container.Resolve<ServicesInitializer>();
    serviceInitializer.Initialize();

    var applicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;

    app.Use<AuthorizeErrorMiddleware>();

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Login"),
        Provider = new CookieAuthenticationProvider
        {
            OnApplyRedirect = e => DotvvmAuthenticationHelper.ApplyRedirectResponse(e.OwinContext, e.RedirectUri)
        }
    });
    app.MapSignalR();

    // use DotVVM
    var dotvvmConfiguration = app.UseDotVVM<DotvvmStartup>(applicationPhysicalPath, options: options =>
    {
        options.AddDefaultTempStorages("temp");

        options.Services.AddSingleton<IViewModelLoader>(serviceProvider => new WindsorViewModelLoader(container));

        options.AddUploadedFileStorage("App_Data/Temp", TimeSpan.FromSeconds(30));
    });

    #if !DEBUG
        dotvvmConfiguration.Debug = false;
    #endif
}  
Martin
  • 455
  • 1
  • 11
  • 34

0 Answers0