C# IAApplicationBuilder dos不包含定义MapSignalR()。app.MapSignalR()在ASP.NET核心上不工作
我想在我的项目中加入SignalR,但我不能在Startup类中添加line app.MapSignalR()时出错。以下是StartUp类:C# IAApplicationBuilder dos不包含定义MapSignalR()。app.MapSignalR()在ASP.NET核心上不工作,c#,asp.net-core,leaflet,signalr,C#,Asp.net Core,Leaflet,Signalr,我想在我的项目中加入SignalR,但我不能在Startup类中添加line app.MapSignalR()时出错。以下是StartUp类: public class Startup { public Startup(IConfiguration configuration{...} public IConfiguration Configuration { get; } // This method gets called by the runtime. U
public class Startup
{
public Startup(IConfiguration configuration{...}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{...}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.MapSignalR(); // ERROR - IApplicaionBuilder dos not contain a definition MapSignalR() and the best extension method overload ' OwinExtensios.MapSignalR(IAppBuilder)' requires a receiver of type 'IAppBuilder'
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
我已经添加了“使用Owin;”但它仍然不起作用。我该怎么办?像这样使用。这是针对.NETCore3.0的+
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/chatHub");
});
}
public void配置服务(IServiceCollection服务)
{
services.AddSignalR();
}
//此方法由运行时调用。使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
app.UseExceptionHandler(“/Error”);
//默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapHub(“/chatHub”);
});
}
阅读更多:
在.net core 2.2中使用以下选项
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("/chatHub");
});
app.usesigner(路由=>
{
routes.MapHub(“/chatHub”);
});
而不是
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/chatHub");
});
app.UseEndpoints(端点=>
{
endpoints.MapHub(“/chatHub”);
});
您可能安装了错误的nuget packageI安装了OWIN IAppBuilder启动界面。不是吗?您需要将signalr安装到Microsoft.AspNetCore.signalr 1.1.0。请尝试此nuget软件包已安装