server.urls Paramter Not Working On Kestrel Server for dotnet Command on ASP.NET Core RC2

Written by William Roush on May 21, 2016 at 3:53 am

Was struggling really hard with getting this command to work:


dotnet run -- --server.urls http://*:5000

Simple command, but it isn’t taking! Well I missed one major thing when upgrading from RC1 to RC2, I need to now pass configuration down to the Kestrel stack, to do that is pretty easy:

        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                .AddCommandLine(args)
                .AddEnvironmentVariables(prefix: "ASPNETCORE_")
                .Build();

            var host = new WebHostBuilder()
                .UseConfiguration(config)
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }

Needed to define the “config” variable and pass it to WebHostBuilder using UseConfiguration(). All fixed!

This entry was posted in .NET and tagged , , on by .

About William Roush

William Roush is currently employed as a Senior Software Developer and independent contractor in Chattanooga, Tennessee. He has more than 12 years of experience in the IT field, with a wide range of exposure including software development, deploying and maintaining virtual infrastructure, storage administration and Windows administration.

2 thoughts on “server.urls Paramter Not Working On Kestrel Server for dotnet Command on ASP.NET Core RC2

  1. John Mark Isaac Madison

    Hey there, I was wondering where I could find the command-line documentation for ” dotnet myproject.dll –sever.urls”.

    I’am running across code examples that use “–urls” instead of “–server.urls”.
    Are these shorthand and longhand versions of the same parameter?

    Reply
    1. William Roush Post author

      `-urls` is likely shorthand, at least in my experience one dash == shorthand.

      According to comments in the source `–server.urls` is mapped to the UseUrl() method. That’s all I’ve seen in relation to the subject: https://github.com/aspnet/KestrelHttpServer/blob/2351c1b558fc6f4312af262aa866fd2c5164761f/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs#L19

      But if the shorthand works, I don’t see any reason you can’t use it.

      Reply

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.