aspnetcore/samples/PlaintextApp/Startup.cs

46 lines
1.4 KiB
C#

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
namespace PlaintextApp
{
public class Startup
{
private static readonly byte[] _helloWorldBytes = Encoding.UTF8.GetBytes("Hello, World!");
public void Configure(IApplicationBuilder app)
{
app.Run((httpContext) =>
{
var response = httpContext.Response;
response.StatusCode = 200;
response.ContentType = "text/plain";
var helloWorld = _helloWorldBytes;
response.ContentLength = helloWorld.Length;
return response.Body.WriteAsync(helloWorld, 0, helloWorld.Length);
});
}
public static Task Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel(options =>
{
options.Listen(IPAddress.Loopback, 5001);
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
return host.RunAsync();
}
}
}