ASP.NET Core - hello world

ASP.NET Core - hello world

Hello world

Hier ein vollständiges und minimales Beispiel, wie eine simple Hello World Anwendung in ASP.NET Core 1 aussehen kann:

 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading.Tasks;
 5using Microsoft.AspNetCore.Builder;
 6using Microsoft.AspNetCore.Hosting;
 7using Microsoft.AspNetCore.Http;
 8using Microsoft.Extensions.DependencyInjection;
 9using Microsoft.Extensions.Logging;
10
11namespace AspNetCore_Basics_HelloWorld
12{
13    public class Program
14    {
15        public static void Main(string[] args)
16        {
17            var host = new WebHostBuilder()
18                .UseKestrel()
19                .UseStartup<Startup>()
20                .Build();
21
22            host.Run();
23        }
24    }
25
26    public class Startup
27    {
28        public void ConfigureServices(IServiceCollection services)
29        {
30        }
31        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory lf)
32        {
33            loggerFactory.AddConsole();
34
35            if (env.IsDevelopment())
36            {
37                app.UseDeveloperExceptionPage();
38            }
39
40            app.Run(async (context) =>
41            {
42                await context.Response.WriteAsync("Hello World!");
43            });
44        }
45    }
46}

Comments

Twitter Facebook LinkedIn WhatsApp