I am running a .NET Core SignalR server on a Console Application. With my code below, I can run the server. But since the clients of this server is another IP Address, I need to setup my SignalR server to run on the current PC's IP Address. Upon running this is what I get:
I need to change the http://localhost:5000
to current host pc's IP address which is 192.168.1.4
and set the port to 8090
. Please see my code below:
Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR(hubOptions => {
hubOptions.EnableDetailedErrors = true;
hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);
});
services.AddCors(options =>
{
options.AddPolicy("SomePolicy", builder => builder
.SetIsOriginAllowed(IsOriginAllowed)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.Build()
);
});
}
private bool IsOriginAllowed(string host)
{
var allowedOrigin = Configuration.GetSection("AcceptedOrigin").Get<string[]>();
return allowedOrigin.Any(origin => origin == host);
}
public void Configure(IApplicationBuilder app)
{
app.UseCors("SomePolicy");
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<RimHub>("/rimHub");
});
}
}
Program.cs
class Program
{
static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
}
On the previous version of SignalR, we can use the .WithUrl('IPADDRESS')
, but with this new version, I do not know how to implement it.