Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IApplicationBuilder dos not contain a definition UseEndpoints. app.UseEndpoints(...) not workin on ASP.NET CORE

I'm trying to incorporate signalR on my project, but when I try to use app.UseEndpoints(...) it gives me an error saying that "IApplicationBuilder does not contain UserEndpoints. Here is the code on my 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?}");
        });
    }
}

What should I do?

My Hub:

 public class MyHub : Microsoft.AspNet.SignalR.Hub
   {
    public async Task PostMarker(string latitude, string longitude) 
    {
        await Clients.All.SendAsync("ReceiveLocation", latitude, longitude);
    }
}
like image 423
Teresa Alves Avatar asked Nov 16 '25 08:11

Teresa Alves


1 Answers

As per your comment, you are targeting .NET Core 2.1, but the UseEndpoints extension method was introduced in 3.0.

To add SignalR in 2.1, firstly make sure you have services.AddSignalR(); in your ConfigureServices method. Secondly, you should use app.UseSignalR in the Configure method, instead of UseEndpoints.

Like so:

app.UseSignalR(route =>
{
    route.MapHub<MyHub>("/myHub");
});
like image 97
Shahzad Avatar answered Nov 19 '25 09:11

Shahzad