IApplicationBuilder 不包含定义 UseEndpoints。 app.UseEndpoints(...) 无法在 ASP.NET 核心上工作
IApplicaionBuilder dos not contain a definition UseEndpoints. app.UseEndpoints(...) not workin on ASP.NET CORE
我正在尝试将 signalR 合并到我的项目中,但是当我尝试使用 app.UseEndpoints(...) 时,它给我一个错误提示“IApplicationBuilder 不包含 UserEndpoints。这是代码在我的 StartUp class:
// 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();
//SIGNAL R - ERROR
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/myHub");
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
我该怎么办?
我的中心:
public class MyHub : Microsoft.AspNet.SignalR.Hub
{
public async Task PostMarker(string latitude, string longitude)
{
await Clients.All.SendAsync("ReceiveLocation", latitude, longitude);
}
}
根据您的评论,您的目标是 .NET Core 2.1,但是 the UseEndpoints
extension method was introduced in 3.0。
要在 2.1 中添加 SignalR,首先确保您的 ConfigureServices
方法中有 services.AddSignalR();
。其次,你应该在 Configure
方法中使用 app.UseSignalR
,而不是 UseEndpoints
.
像这样:
app.UseSignalR(route =>
{
route.MapHub<MyHub>("/myHub");
});
我正在尝试将 signalR 合并到我的项目中,但是当我尝试使用 app.UseEndpoints(...) 时,它给我一个错误提示“IApplicationBuilder 不包含 UserEndpoints。这是代码在我的 StartUp class:
// 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();
//SIGNAL R - ERROR
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/myHub");
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
我该怎么办?
我的中心:
public class MyHub : Microsoft.AspNet.SignalR.Hub
{
public async Task PostMarker(string latitude, string longitude)
{
await Clients.All.SendAsync("ReceiveLocation", latitude, longitude);
}
}
根据您的评论,您的目标是 .NET Core 2.1,但是 the UseEndpoints
extension method was introduced in 3.0。
要在 2.1 中添加 SignalR,首先确保您的 ConfigureServices
方法中有 services.AddSignalR();
。其次,你应该在 Configure
方法中使用 app.UseSignalR
,而不是 UseEndpoints
.
像这样:
app.UseSignalR(route =>
{
route.MapHub<MyHub>("/myHub");
});