.NET Framework 4.6.1 services.addSignalR 和 app.UseSignalR 不工作
.NET Framework 4.6.1 services.addSignalR and app.UseSignalR not working
我正在尝试使用 SignalR 创建聊天室。我知道那里有很多示例,但不知何故它无法与我的 .Net Framework 应用程序一起使用。我们尝试了很多解决方案,因为每个旅游网站都有不同的演练。
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Database;
using Microsoft.AspNet.SignalR;
namespace Chatroom
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("fiver",
policy => policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
});
services.AddSignalR();
services.AddSingleton<FanZContext, FanZContext>(x => new FanZContext());
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseSignalR(routes =>
{
routes.MapHub<SensorHub>("sensor");
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
语法错误:'IServiceCollection' 不包含 'AddSignalR' 的定义,并且找不到接受类型 'IServiceCollection' 的第一个参数的扩展方法 'AddSignalR'(您是缺少 using 指令或程序集引用?)
链接一个在 .Net Framework 4.6.1 上工作的简单示例项目会有所帮助,我在谷歌上搜索了很多教程,我现在很绝望。
提前致谢!
您不能混合和匹配 SignalR 服务器和客户端的版本
来自 Alpha 发布博客 post here
One of the consequences of this is that SignalR for ASP.NET Core is not compatible with previous versions of SignalR. This means that you cannot use the old server with the new clients or the old clients with the new server.
我正在尝试使用 SignalR 创建聊天室。我知道那里有很多示例,但不知何故它无法与我的 .Net Framework 应用程序一起使用。我们尝试了很多解决方案,因为每个旅游网站都有不同的演练。
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Database;
using Microsoft.AspNet.SignalR;
namespace Chatroom
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("fiver",
policy => policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
});
services.AddSignalR();
services.AddSingleton<FanZContext, FanZContext>(x => new FanZContext());
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseSignalR(routes =>
{
routes.MapHub<SensorHub>("sensor");
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
语法错误:'IServiceCollection' 不包含 'AddSignalR' 的定义,并且找不到接受类型 'IServiceCollection' 的第一个参数的扩展方法 'AddSignalR'(您是缺少 using 指令或程序集引用?)
链接一个在 .Net Framework 4.6.1 上工作的简单示例项目会有所帮助,我在谷歌上搜索了很多教程,我现在很绝望。
提前致谢!
您不能混合和匹配 SignalR 服务器和客户端的版本
来自 Alpha 发布博客 post here
One of the consequences of this is that SignalR for ASP.NET Core is not compatible with previous versions of SignalR. This means that you cannot use the old server with the new clients or the old clients with the new server.