Blog

Get Started with ASP.NET

Below you will find the steps to build your first ASP.NET Core app. See Get Started with ASP.NET if you are looking to get started with ASP.NET and the .NET Framework on Windows. Learn more about the difference between ASP.NET and ASP.NET Core.

Download.NET Core
Free .NET command-line tools for Windows, Mac, and Linux

Let's start by building a simple "Hello, world!" app.

  1. 1

    Install .NET Core. See installation steps for Windows, macOS, and Linux here.

  2. 2

    Create a new .NET Core project:

    1. mkdir aspnetcoreapp
    2. cd aspnetcoreapp
    3. dotnet new web
  3. 3

    Restore the packages

    1. dotnet restore
  4. 4

    Update the code in Startup.cs to return a message of our choice

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole();
    
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
    
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello from ASP.NET Core!");
        });
    }
    
  5. 5

    Run the app (the dotnet run command will build the app when it's out of date)

    1. dotnet run
  6. 6

    Browse to http://localhost:5000

  7. 7

    Press Ctrl+C to stop the app

Now let's enable support for static files.

  1. 1

    Add the static file middleware in Startup.cs

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole();
    
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
    
        app.UseStaticFiles();
    
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello from ASP.NET Core!");
        });
    }
  2. 2

    Add the static file middleware NuGet package

    1. dotnet add package Microsoft.AspNetCore.StaticFiles
    2. dotnet restore
  3. 3

    Add index.html file to the wwwroot folder

    <!DOCTYPE html>
    <html>
    <body>
        <h1>Static file from ASP.NET Core!</h1>
    </body>
    </html>
  4. 4

    Build and run the app

    1. dotnet run
  5. 5

    Browse to http://localhost:5000/index.html

  6. That’s it!

    Next up, try building your first ASP.NET Core MVC app with Visual Studio or Visual Studio Code.

    Also checkout out the docs and tutorials.