Qsprec
Qsprec

Reputation: 275

Error: SignalRRouteExtension.Mapconnection is obsolete. use MapSignalR in Owin Startup class

I am developing a ASP.NET MVC application with ASP.NET SignalR. But i am getting error and couldn't find how to solve this. This is my global.asax class and I am getting error at here when i started the project:

 public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);

        //This is what I added and this is where i am getting the error.
        RouteTable.Routes.MapConnection<NfcConnection>("echo", "/echo");
    }
}

And my connection class like at the bottom

public class NfcConnection : PersistentConnection
{
    protected override Task OnConnected(IRequest request, string connectionId)
    {
        string msg = string.Format(
            "A new user {0} has just joined. (ID: {1})",
            request.QueryString["name"], connectionId);
        return Connection.Broadcast(msg);
    }

    protected override Task OnReceived(IRequest request, string connectionId, string data)
    {

        string msg = string.Format(
            "{0}: {1}", request.QueryString["name"], data);
        return Connection.Broadcast(msg);
    }
}

This is the part that will broadcast the data which coming from the client. And also my startup class for owin is like that;

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

}

When i start the project this line

RouteTable.Routes.MapConnection<NfcConnection>("echo", "/echo");

giving me this error;

Error'System.Web.Routing.SignalRRouteExtensions.MapConnection<T>(System.Web.Routing.RouteCollection, string, string)' is obsolete: 'Use IAppBuilder.MapSignalR<TConnection> in an Owin Startup class.

How can i solve this?

Upvotes: 0

Views: 2617

Answers (1)

Pawel
Pawel

Reputation: 31610

Remove:

RouteTable.Routes.MapConnection<NfcConnection>("echo", "/echo");

and change:

app.MapSignalR();

to:

app.MapSignalR<NfcConnection>("/echo");

Upvotes: 1

Related Questions