我正在使用ASP.NET SignalR开发ASP.NET MVC应用程序。但我收到错误,无法找到解决方法。 这是我的global.asax类,当我启动项目时,我在这里遇到错误:
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");
}
}
我的连接类就像在底部
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);
}
}
这是广播来自客户端的数据的部分。 而且我的owin启动课就是这样;
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
当我开始项目这一行
RouteTable.Routes.MapConnection<NfcConnection>("echo", "/echo");
给我这个错误;
Error'System.Web.Routing.SignalRRouteExtensions.MapConnection<T>(System.Web.Routing.RouteCollection, string, string)' is obsolete: 'Use IAppBuilder.MapSignalR<TConnection> in an Owin Startup class.
我该如何解决这个问题?
答案 0 :(得分:1)
卸下:
RouteTable.Routes.MapConnection<NfcConnection>("echo", "/echo");
并改变:
app.MapSignalR();
为:
app.MapSignalR<NfcConnection>("/echo");