当前位置: 首页>>代码示例>>C#>>正文


C# WebHostBuilder.Run方法代码示例

本文整理汇总了C#中Microsoft.AspNetCore.Hosting.WebHostBuilder.Run方法的典型用法代码示例。如果您正苦于以下问题:C# WebHostBuilder.Run方法的具体用法?C# WebHostBuilder.Run怎么用?C# WebHostBuilder.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNetCore.Hosting.WebHostBuilder的用法示例。


在下文中一共展示了WebHostBuilder.Run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        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();

            // Delete UNIX pipe if it exists at startup (eg. previous process crashed before cleaning it up)
            var addressFeature = host.ServerFeatures.Get<IServerAddressesFeature>();
            var url = ServerAddress.FromUrl(addressFeature.Addresses.First());
            if (url.IsUnixPipe && File.Exists(url.UnixPipePath))
            {
                Console.WriteLine("UNIX pipe {0} already existed, deleting it.", url.UnixPipePath);
                File.Delete(url.UnixPipePath);
            }

            host.Run();
        }
开发者ID:Daniel15,项目名称:Website,代码行数:25,代码来源:Startup.cs

示例2: Main

        public static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("KestrelHelloWorld <url to host>");
                return 1;
            }

            var url = new Uri(args[0]);
            Args = string.Join(" ", args);

            var host = new WebHostBuilder()
                .UseServer("Microsoft.AspNetCore.Server.Kestrel")
                .UseUrls(url.ToString())
                .UseStartup<Startup>()
                .Build();

            ServerCancellationTokenSource = new CancellationTokenSource();

            // shutdown server after 20s.
            var shutdownTask = Task.Run(async () =>
            {
                await Task.Delay(20000);
                ServerCancellationTokenSource.Cancel();
            });

            host.Run(ServerCancellationTokenSource.Token);
            shutdownTask.Wait();

            return 0;
        }
开发者ID:krwq,项目名称:cli,代码行数:31,代码来源:Startup.cs

示例3: Main

 public static void Main(string[] args)
 {
     var host = new WebHostBuilder()
     .UseStartup<TestStartup>()
     .Build();
     host.Run();
 }
开发者ID:digipolisantwerp,项目名称:serviceagents_aspnetcore,代码行数:7,代码来源:TestStartup.cs

示例4: Main

        public static void Main(string[] args)
        {
            while (true)
            {
                var host = new WebHostBuilder()
                    .UseKestrel()
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseIISIntegration()
                    .UseStartup<Startup>()
                    .Build();

                var lifetime = (IApplicationLifetime)host.Services.GetService(typeof(IApplicationLifetime));
                Task.Run(() =>
                {

                    while (true)
                    {
                        var line = Console.ReadLine();
                        if (line == "r")
                        {
                            Console.WriteLine("Restarting");
                            lifetime.StopApplication();
                            break;
                        }
                    }
                });

                host.Run();
            }
        }
开发者ID:pakrym,项目名称:signoffs,代码行数:30,代码来源:Program.cs

示例5: Main

        public static void Main(string[] args)
        {
            var currentDirectory = Directory.GetCurrentDirectory();

            var host = new WebHostBuilder()
                .UseIISIntegration()
                .UseKestrel()
                .UseContentRoot(currentDirectory)
                .UseStartup<Startup>()
                .Build();

            using (host)
            {
                using (var cts = new CancellationTokenSource())
                {
                    host.Run((services) =>
                    {
                        var orchardHost = new OrchardHost(
                            services,
                            System.Console.In,
                            System.Console.Out,
                            args);

                        orchardHost
                            .RunAsync()
                            .Wait();

                        cts.Cancel();

                    }, cts.Token, "Application started. Press Ctrl+C to shut down.");
                }
            }
        }
开发者ID:vairam-svs,项目名称:Orchard2,代码行数:33,代码来源:Program.cs

示例6: Main

        public static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                .AddJsonFile(HostingJsonFileName, optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .AddCommandLine(args)
                .Build();

            var host = new WebHostBuilder()
                .UseConfiguration(configuration)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseKestrel(
                    options =>
                    {
                        // TODO: for Kestrel to serve HTTPS, a certificate is required
                        //options.UseHttps()
                        // Do not add the Server HTTP header when using the Kestrel Web Server.
                        options.AddServerHeader = false;
                    })
                // $Start-WebServer-IIS$
                .UseIISIntegration()
                // $End-WebServer-IIS$
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
开发者ID:miroslavpopovic,项目名称:timetracker,代码行数:27,代码来源:Program.cs

示例7: Main

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

            var host = new WebHostBuilder()
                .UseConfiguration(config) // Default set of configurations to use, may be subsequently overridden 
              //.UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory
                .UseUrls("http://*:1000", "https://*:902")
                .UseEnvironment("Development")
                .UseWebRoot("public")
                .ConfigureServices(services =>
                {
                    // Configure services that the application can see
                    services.AddSingleton<IMyCustomService, MyCustomService>();
                })
                .Configure(app =>
                {
                    // Write the application inline, this won't call any startup class in the assembly

                    app.Use(next => context =>
                    {
                        return next(context);
                    });
                })
                .Build();

            host.Run();
        }
开发者ID:akrisiun,项目名称:Hosting,代码行数:33,代码来源:StartupFullControl.cs

示例8: Main

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

            var restartTime = 0;

            Restart:

            try
            {
                host.Run();
            }
            catch (Exception ex)
            {
                Logger.Error("Unhandled exception occured while host is running.", ex);
                if (restartTime <= MaxRestartTime)
                {
                    restartTime++;

                    Logger.Info("Trying to restart...");

                    goto Restart;
                }
            }

            ClearUp();
        }
开发者ID:yhvicey,项目名称:ConfigSync,代码行数:33,代码来源:Program.cs

示例9: Main

        public static void Main(string[] args)
        {
            if (Debugger.IsAttached)
            {
                Environment.SetEnvironmentVariable(
                    "ASPNETCORE_ENVIRONMENT", 
                    EnvironmentName.Development);
            }	    
	    
            var config = new ConfigurationBuilder()
                	  .AddJsonFile("hosting.json", optional: true)
        		  .AddEnvironmentVariables("ASPNETCORE_")
                	  .AddCommandLine(args)
                	  .Build();

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

            host.Run();
        }
开发者ID:rfinochi,项目名称:confsamples,代码行数:25,代码来源:Program.cs

示例10: Main

        public static void Main(string[] args)
        {
            var application = new WebHostBuilder()
                .UseConfiguration(WebHostConfiguration.GetDefault(args))
                .UseStartup<Startup>()
                .Build();

            application.Run();
        }
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:9,代码来源:Startup.cs

示例11: Main

        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseDefaultConfiguration(args)
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
开发者ID:aL3891,项目名称:RioSharp,代码行数:9,代码来源:Startup.cs

示例12: Main

        public static void Main(string[] args)
        {
            var host = new WebHostBuilder().UseKestrel()
                                           .UseContentRoot(Directory.GetCurrentDirectory())
                                           .UseStartup<Startup>()
                                           .Build();

            host.Run();
        }
开发者ID:ColinDabritz,项目名称:Docs,代码行数:9,代码来源:Program.cs

示例13: Main

        public static void Main(string[] args)
        {
            var builder = new WebHostBuilder()
                .UseKestrel()
                .UseStartup<Startup>()
                .Build();

            builder.Run();
        }
开发者ID:yonglehou,项目名称:ServiceFabric-Http,代码行数:9,代码来源:Startup.cs

示例14: Main

        // Entry point for the application.
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
              //.UseKestrel()
                .UseStartup<StartupHelloWorld>()
                .Build();

            host.Run();
        }
开发者ID:akrisiun,项目名称:Hosting,代码行数:10,代码来源:StartupHelloWorld.cs

示例15: Main

        public static void Main(string[] args)
        {
            var app = new WebHostBuilder()
                .UseServer("Microsoft.AspNetCore.Server.Kestrel")
                .UseUrls("http://*:5004")
                .UseStartup<Startup>()
                .Build();

            app.Run();
        }
开发者ID:andy250,项目名称:Sandbox,代码行数:10,代码来源:Program.cs


注:本文中的Microsoft.AspNetCore.Hosting.WebHostBuilder.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。