0

How to use machine IP address ( https://192.168.1.102:5001) instead of localhost (https://localhost:5000) to host/run dotnet core application using Kestrel(Without IIS):

I am using the following configuration

  Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.ConfigureKestrel(serverOptions =>
        {
            serverOptions.Listen(IPAddress.Loopback, 5000);
            serverOptions.Listen(IPAddress.Loopback, 5001, 
                listenOptions =>
                {
                    listenOptions.UseHttps("cert.pfx", 
                        "123");
                });
        })
        .UseStartup<Startup>();
    });

I know we can use .UseUrls("http://192.168.0.101:5001") as follows, but this does not work with https

 Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.
                    UseKestrel()
            .UseUrls("http://192.168.0.101:5001")
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration().UseStartup<Startup>();
                });

Any suggestion or guide would be appreciated, thanks in advance!

Arun Saini
  • 6,714
  • 1
  • 19
  • 22

1 Answers1

1

Finally, I found the silly mistake I was making.

I had to pass ip address as follows:

serverOptions.Listen(IPAddress.Parse("192.168.0.101"), 5001, ....
Arun Saini
  • 6,714
  • 1
  • 19
  • 22