HttpSysServer/samples/SelfHostServer/Startup.cs

49 строки
1.5 KiB
C#
Исходник Обычный вид История

2014-06-17 01:24:20 +04:00
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
2014-04-01 00:05:03 +04:00
namespace SelfHostServer
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Server options can be configured here instead of in Main.
2016-12-16 01:38:59 +03:00
services.Configure<HttpSysOptions>(options =>
{
2016-12-16 01:38:59 +03:00
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
});
}
2017-05-05 22:42:01 +03:00
public void Configure(IApplicationBuilder app)
2014-04-01 00:05:03 +04:00
{
app.Run(async context =>
{
2017-01-11 23:00:19 +03:00
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello world from " + context.Request.Host + " at " + DateTime.Now);
2014-04-01 00:05:03 +04:00
});
}
2015-12-18 03:47:55 +03:00
public static void Main(string[] args)
{
2016-01-18 02:58:30 +03:00
var host = new WebHostBuilder()
2017-05-05 22:42:01 +03:00
.ConfigureLogging(factory => factory.AddConsole())
2015-12-18 03:47:55 +03:00
.UseStartup<Startup>()
2016-12-16 01:38:59 +03:00
.UseHttpSys(options =>
{
2017-02-28 06:40:38 +03:00
options.UrlPrefixes.Add("http://localhost:5000");
2016-12-16 01:38:59 +03:00
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
})
2015-12-18 03:47:55 +03:00
.Build();
2016-01-18 02:58:30 +03:00
host.Run();
2015-12-18 03:47:55 +03:00
}
2014-04-01 00:05:03 +04:00
}
}