Using .MapOwinRoute() instead of the OwinStartup / Configuration class - negotiate returns 404

StackOverflow https://stackoverflow.com/questions/21278065

Pergunta

I'm working on an app using SignalR 2 and am running into problems mapping SignalR through the .MapOwinRoute() extension method for the ASP.net 4 RouteTable.Routes. Like:

RouteTable.Routes.MapOwinRoute("signalr.hubs", "signalr/hubs", a => a.MapSignalR());

also added to Web.Config:

<appSettings>
    <add key="owin:AutomaticAppStartup" value="false" />
</appSettings

It maps up. Navigating to /signalr/hubs gives me the hubs proxies, but when I connect with my code:

$(function () {
   var orderProcessing = $.connection.orderProcessing;
   $.connection.hub.start().done(function () {
      orderProcessing.server.doStuff();
   });
});

The route /signalr/negotiate returns a 404.

Everything works fine when I do it like this:

[assembly: OwinStartup(typeof(Web.Startup))]

namespace Web
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

The problem is that using the OwinStartup is not an option for me, as I need to configure SignalR with my own dependency resolver linking it to the general IOC container I use and it is not ready at the point of OwinStartup. I also need to configure the JSON serializer with custom options that also gets configured at a later stage.

Can't quite figure out what I'm missing here.

Foi útil?

Solução

You don't want to map a route to want to map a prefix (path). Also, you're using the wrong url and wrong IAppBuilder overload.

RouteTable.Routes.MapOwinPath("/signalr", app => app.RunSignalR());

The above logic takes any path that starts with SignalR and passes it to the SignalR middleware.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top