static void

Startup

static void Main

Asp.Net Core is a true console application, with a public static void Main(string[] args)

In .net core 3.1 it looks like this. In asp use WebHost (in .net6 you can use WebApplication, which removes the need for Startup.cs)

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();>
            });
}

For Dependency Injection with, say, Autofac, add Autofac.Extensions.DependencyInjection:

Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory()) //etc

See configuration for Serilog logging and NLog logging

In .net 6, old projects aren't upgraded, but new ones have the "class-less" program.cs format and a more imperative style.

var builder = WebApplication.CreateBuilder(args);
builder.Services..AddControllersWithViews();
var app = builder.Build();
//trimmed app.Use stuff
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
  name:"default"
  pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();

.Net Core 1

In RC1 it was in Startup.cs; from RC2 it is in Program.cs

public static void Main(string[] args)
{
    var host = new WebHostBuilder(args)
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();
    host.Run();
}

For Windows/IIS, you don't need to change this.

Startup.cs

In classic Asp.net, you configured things in Global.asax. In Core 1-5, you use Startup.cs. In .net 6 it's gone again.

There is no base class or interface. The name and standard methods are conventions. You can have multiple "Startup" classes, but only one is used... either the project namespace, or it uses namespace alphabetical order(!).

Net6 - if you use WebApplication.CreateBuilder(args), you can't use Startup in the same way. But you can new it up and use it explicitly.

//using the new WebApplication instead of WebHost
var builder = WebApplication.CreateBuilder(args);
//just new up startup with the configuration
var startup = new Startup(builder.Configuration);
//then add the services (AddControllersWithViews)
startup.ConfigureServices(builder.Services);
//as before
var app = builder.Build();
//then do the configuration
startup.Configure(app, app.Environment);
//as before
app.Run();

Structure

The minimum:

public class Startup
{
    //REQUIRED: configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello :)");
        });
    }
}

MethodNotesArguments
Startup.Configure(IApplicationBuilder app, ...) Required. Normally app.UseMvc() IApplicationBuilder (required),
IWebHostEnvironment
Startup.ConfigureServices(optional) build dependency injection IServiceCollection (required, only input)
ConstructorInitial configuration, initialize "application" variables such as configuration IConfiguration,
IWebHostEnvironment

IApplicationBuilder must only be used for Configure, and IServiceCollection must only be used for ConfigureServices

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace CoreWeb
{
    public class Startup
    {
        public Startup(IConfiguration configuration)         {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddControllers();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder appIWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}