Skip to content

Instantly share code, notes, and snippets.

@Pzixel
Created December 6, 2017 13:04
Show Gist options
  • Save Pzixel/6a61a4543a82663c5b31760c974ea05a to your computer and use it in GitHub Desktop.
Save Pzixel/6a61a4543a82663c5b31760c974ea05a to your computer and use it in GitHub Desktop.
Self-hosted web application
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace SelfHostAspCoreExample
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddDebug();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
namespace SelfHostAspCoreExample.Controllers
{
public class TestController
{
public string GetHelloWorld() => "Hello world!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment