Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            var configBuilder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json");

            var configuration = configBuilder.Build();

            var hostBuilder = new WebHostBuilder();

            // set urls and environment
            hostBuilder
                .UseUrls(configuration["urls"])
                .UseEnvironment(configuration["environment"]);

            // set other common things
            hostBuilder
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>();

            var host = hostBuilder.Build();

            host.Run();
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                .AddCommandLine(args)
                .AddEnvironmentVariables(prefix: "ASPNETCORE_")
                .Build();

            var builder = new WebHostBuilder()
                .UseConfiguration(config)
                .UseIISIntegration()
                .UseStartup("MusicStore.Web");

            if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.WebListener", System.StringComparison.Ordinal))
            {
                var environment = builder.GetSetting("environment") ??
                    Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

                if (string.Equals(environment, "NtlmAuthentication", System.StringComparison.Ordinal))
                {
                    // Set up NTLM authentication for WebListener like below.
                    // For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or
                    // modify the applicationHost.config to enable NTLM.
                    builder.UseWebListener(options =>
                    {
                        options.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.NTLM;
                        options.ListenerSettings.Authentication.AllowAnonymous = false;
                    });
                }
                else
                {
                    builder.UseWebListener();
                }
            }
            else
            {
                builder.UseKestrel();
            }

            var host = builder.Build();

            host.Run();
        }
        /// <summary>
        /// Starts listening at the specified port.
        /// </summary>
        public void Start()
        {
            Startup.Listener = this;
           
            m_host = new WebHostBuilder();

            HttpsConnectionFilterOptions httpsOptions = new HttpsConnectionFilterOptions();
            httpsOptions.CheckCertificateRevocation = false;
            httpsOptions.ClientCertificateMode = ClientCertificateMode.NoCertificate;
            httpsOptions.ServerCertificate = m_serverCert;
            httpsOptions.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;

            m_host.UseKestrel(options =>
            {
                options.NoDelay = true;
                options.UseHttps(httpsOptions);
            });

            m_host.UseContentRoot(Directory.GetCurrentDirectory());
            m_host.UseStartup<Startup>();
            m_host.Build();

            m_host.Start(Utils.ReplaceLocalhost(m_uri.ToString()));
        }
Ejemplo n.º 4
0
        public static int Main(string[] args)
        {
            // Add command line configuration source to read command line parameters.
            var config = new ConfigurationBuilder()
                .AddCommandLine(args)
                .Build();

            Server = config["server"] ?? "Kestrel";

            var builder = new WebHostBuilder()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseConfiguration(config)
                .UseStartup<Startup>();

            // The default listening address is http://localhost:5000 if none is specified.
            // Replace "localhost" with "*" to listen to external requests.
            // You can use the --urls flag to change the listening address. Ex:
            // > dotnet run --urls http://*:8080;http://*:8081

            // Uncomment the following to configure URLs programmatically.
            // Since this is after UseConfiguraiton(config), this will clobber command line configuration.
            //builder.UseUrls("http://*:8080", "http://*:8081");

            // If this app isn't hosted by IIS, UseIISIntegration() no-ops.
            // It isn't possible to both listen to requests directly and from IIS using the same WebHost,
            // since this will clobber your UseUrls() configuration when hosted by IIS.
            // If UseIISIntegration() is called before UseUrls(), IIS hosting will fail.
            builder.UseIISIntegration();

            if (string.Equals(Server, "Kestrel", StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("Running demo with Kestrel.");

                builder.UseKestrel(options =>
                {
                    if (config["threadCount"] != null)
                    {
                        options.ThreadCount = int.Parse(config["threadCount"]);
                    }
                });
            }
            else if (string.Equals(Server, "WebListener", StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("Running demo with WebListener.");

                builder.UseWebListener(options =>
                {
                    // AllowAnonymous is the default WebListner configuration
                    options.Listener.AuthenticationManager.AuthenticationSchemes =
                        AuthenticationSchemes.AllowAnonymous;
                });
            }
            else
            {
                Console.WriteLine($"Error: Unknown server value: '{Server}'. The valid server options are 'Kestrel' and 'WebListener'.");
                Console.WriteLine("IIS cannot be specified at runtime since it does not support self-hosting.");
                return 1;
            }

            // ASPNETCORE_PORT is the port that IIS proxies requests to.
            if (Environment.GetEnvironmentVariable($"ASPNETCORE_PORT") != null)
            {
                if (string.Equals(Server, "WebListener", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Error: WebListener cannot be used with the ASP.NET Core Module for IIS.");
                    return 1;
                }

                Server = "IIS/Kestrel";

                Console.WriteLine("Hosted by IIS.");
            }

            var host = builder.Build();
            host.Run();

            return 0;
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            Args = args;

            Console.WriteLine();
            Console.WriteLine("ASP.NET Core Benchmarks");
            Console.WriteLine("-----------------------");

            Console.WriteLine($"Current directory: {Directory.GetCurrentDirectory()}");

            var config = new ConfigurationBuilder()
                .AddCommandLine(args)
                .AddEnvironmentVariables(prefix: "ASPNETCORE_")
                .AddJsonFile("hosting.json", optional: true)
                .Build();

            Server = config["server"] ?? "Kestrel";

            var webHostBuilder = new WebHostBuilder()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseConfiguration(config)
                .UseStartup<Startup>()
                .ConfigureServices(services => services
                    .AddSingleton(new ConsoleArgs(args))
                    .AddSingleton<IScenariosConfiguration, ConsoleHostScenariosConfiguration>()
                    .AddSingleton<Scenarios>()
                );

            if (String.Equals(Server, "Kestrel", StringComparison.OrdinalIgnoreCase))
            {
                var threads = GetThreadCount(config);
                webHostBuilder = webHostBuilder.UseKestrel((options) =>
                {
                    if (threads > 0)
                    {
                        options.ThreadCount = threads;
                    }
                });
            }
            else if (String.Equals(Server, "WebListener", StringComparison.OrdinalIgnoreCase))
            {
                webHostBuilder = webHostBuilder.UseWebListener();
            }
            else
            {
                throw new InvalidOperationException($"Unknown server value: {Server}");
            }

            var webHost = webHostBuilder.Build();

            Console.WriteLine($"Using server {Server}");
            Console.WriteLine($"Server GC is currently {(GCSettings.IsServerGC ? "ENABLED" : "DISABLED")}");

            var nonInteractiveValue = config["NonInteractive"];
            if (nonInteractiveValue == null || !bool.Parse(nonInteractiveValue))
            {
                StartInteractiveConsoleThread();
            }

            webHost.Run();
        }