Пример #1
0
        public static void Main(string[] args)
        {
            //
            // Build Config
            var            configHelper = new ConfigurationHelper(args);
            IConfiguration config       = configHelper.Build();

            //
            // Host
            using (var host = new WebHostBuilder()
                              .UseContentRoot(configHelper.RootPath)
                              .UseUrls("https://*:55539")                     // Config can override it. Use "urls":"https://*:55539"
                              .UseConfiguration(config)
                              .ConfigureServices(s => s.AddSingleton(config)) // Configuration Service
                              .UseStartup <Startup>()
                              .UseWebListener(o => {
                //
                // Kernel mode Windows Authentication
                o.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;

                //
                // Need anonymous to allow CORS preflight requests
                // app.UseWindowsAuthentication ensures (if needed) the request is authenticated to proceed
                o.ListenerSettings.Authentication.AllowAnonymous = true;
            })
                              .Build()
                              .UseHttps()) {
                string serviceName = config.GetValue <string>("serviceName")?.Trim();

                if (!string.IsNullOrEmpty(serviceName))
                {
                    //
                    // Run as a Service
                    Log.Information($"Running as service: {serviceName}");
                    new ServiceHelper(serviceName).Run(token => host.Run(token))
                    .Wait();
                }
                else
                {
                    //
                    // Run interactive
                    host.Run();
                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            //
            // Build Config
            var            configHelper = new ConfigurationHelper(args);
            IConfiguration config       = configHelper.Build();

            //
            // Initialize runAsAService local variable
            string serviceName   = config.GetValue <string>("serviceName")?.Trim();
            bool   runAsAService = !string.IsNullOrEmpty(serviceName);

            //
            // Host
            using (var host = new WebHostBuilder()
                              .UseContentRoot(configHelper.RootPath)
                              .ConfigureLogging((hostingContext, logging) => {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));

                //
                // Console log is not available in running as a Service
                if (!runAsAService)
                {
                    logging.AddConsole();
                }

                logging.AddDebug();
                logging.AddEventLog(new EventLogSettings()
                {
                    SourceName = EventSourceName
                });
            })
                              .UseUrls("https://*:55539")                     // Config can override it. Use "urls":"https://*:55539"
                              .UseConfiguration(config)
                              .ConfigureServices(s => s.AddSingleton(config)) // Configuration Service
                              .UseStartup <Startup>()
                              .UseHttpSys(o => {
                //
                // Kernel mode Windows Authentication
                o.Authentication.Schemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;

                //
                // Need anonymous to allow CORS preflight requests
                // app.UseWindowsAuthentication ensures (if needed) the request is authenticated to proceed
                o.Authentication.AllowAnonymous = true;
            })
                              .Build()
                              .UseHttps()) {
                if (runAsAService)
                {
                    //
                    // Run as a Service
                    Log.Information($"Running as service: {serviceName}");
                    host.RunAsService();
                }
                else
                {
                    //
                    // Run interactive
                    host.Run();
                }
            }
        }