Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet run web site with specific url

How can I specify using dotnet cli to run my web app using specific configurations. I know hosting.json can be used but I did not find any documentation how to do this and how this relates to the dotnet cli.

like image 722
mbr Avatar asked May 20 '16 16:05

mbr


2 Answers

Look at this sample: https://github.com/aspnet/Security/blob/dev/samples/CookieSample/Program.cs#L11

Tweaked for command line:

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

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

        host.Run();
    }

Then call dotnet run server.urls=http://localhost:5001/

like image 86
Tratcher Avatar answered Sep 26 '22 19:09

Tratcher


Try .UseUrls on Program.cs with specific port.

public class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseUrls("http://localhost:5020")
                .Build();

            host.Run();
        }
    }
like image 29
Hasan Tuna Oruç Avatar answered Sep 25 '22 19:09

Hasan Tuna Oruç