本文整理汇总了C#中Microsoft.AspNetCore.Hosting.WebHostBuilder.UseWebListener方法的典型用法代码示例。如果您正苦于以下问题:C# WebHostBuilder.UseWebListener方法的具体用法?C# WebHostBuilder.UseWebListener怎么用?C# WebHostBuilder.UseWebListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNetCore.Hosting.WebHostBuilder
的用法示例。
在下文中一共展示了WebHostBuilder.UseWebListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
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();
}
示例2: Main
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;
}
示例3: Main
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();
}