Author : MD TAREQ HASSAN

SignalR in ASP.Net Core

ConfigureServices

Startup.cs

public class Startup
{

    public void ConfigureServices(IServiceCollection services)
    {
        //... ... ...
		
		services.AddRazorPages();
		services.AddSignalR();
    }

    public void Configure(IApplicationBuilder app)
    {
        //... ... ...
    }
}

Configure

Startup.cs

public class Startup
{

    public void ConfigureServices(IServiceCollection services)
    {
        //... ... ...
    }

    public void Configure(IApplicationBuilder app)
    {
		// ... ... ...
	
		app.UseRouting();

		app.UseAuthorization();

		app.UseEndpoints(endpoints =>
		{
			endpoints.MapRazorPages();
			endpoints.MapHub<ChatHub>("/chatHub");
		});
    }
}

Allow CORS

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
	// ... ... ...
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{

	// ... ... ...
	
	app.UseCors(builder => {
		builder.WithOrigins("https://www.hovermind.com")
		.AllowAnyHeader()
		.WithMethods("GET", "POST")
		.AllowCredentials();
	});
	
	// ... ... ...
}