Reputation: 5078
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.
Upvotes: 2
Views: 2639
Reputation: 71
Because you are using WebHost.CreateDefaultBuilder, Kestrel is used as web server (see Microsoft Documentation).
You can find details at Microsoft to configure Kestrel (e.g. via appsettings.json or in Startup). Examples can also be found here.
How did you use .WithUrl on the server side in the past? I would rather think that the method is used on the client side.
Upvotes: 1