Carl Rippon

Building SPAs

Carl Rippon
BlogBooks / CoursesAbout
This site uses cookies. Click here to find out more

ASP.NET Core hello World

March 21, 2015
dotnet

In this post, we’ll create an ASP.NET Core app that contains a page containing “hello world” and then change the app to use the ASP.NET welcome page …

Create an empty web project

When you create a new project, select ASP.NET Web Application from the list of templates. Don’t worry about the framework version on this dialog.

new asp.net app

In this example we are then going to select ASP.NET Core Preview Empty from the list of ASP.NET templates.

new asp.net blank app

Configure startup

The entry point for an ASP.NET Core app happens in Startup.cs.

The ConfigureServices method is used to set up the services that the app needs to use - as the name suggests!

The Configure method is used to define what happens during the request pipeline. We can use IApplicationBuilder.Run() in order to do a very simple hello world.

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
    }

    public void Configure(IApplicationBuilder app)
    {
        app.Run(async context =>
        {
            await context.Response.WriteAsync("Hello World");
        });
    }
}

If you run the project, you should receive “Hello World” on a web page.

helloworldpage

Using a welcome page

We can use the standard ASP.NET welcome page instead of our “Hello World” page by instructing the request pipeline to do so:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseWelcomePage();
    }
}

For this to compile, you’ll need to add a dependency on Microsoft.AspNet.Diagnostics

helloworlddiagdep

Now, when you run the project, you should receive the ASP.NET welcome page.

helloworldwelcome

If you to learn about using React with ASP.NET Core you might find my book useful:

ASP.NET Core 5 and React

ASP.NET Core 5 and React
Find out more

Want more content like this?

Subscribe to receive notifications on new blog posts and courses

Required
© Carl Rippon
Privacy Policy