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.
Let's start by building a simple "Hello, world!" app.
-
Install .NET Core. See installation steps for Windows, macOS and Linux here.
-
Download the sample and unzip it.
-
Restore the packages
dotnet restore
- Update the code in Startup.cs to return a message of your choice
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Run(context =>
{
return context.Response.WriteAsync("Hello from ASP.NET Core!");
});
}
}
- Run the app (the dotnet run command will build the app when it's out of date)
dotnet run
- Browse to http://localhost:5000
- Press Ctrl+C to stop the app
Now let's enable support for static files.
- Add the static file middleware in Startup.cs
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.Run(context =>
{
return context.Response.WriteAsync("Hello from ASP.NET Core!");
});
}
}
- Add a wwwroot folder with an index.html file
<!DOCTYPE html>
<html>
<body>
<h1>Static file from ASP.NET Core!</h1>
</body>
</html>
- Build and run the app
dotnet run
- Browse to http://localhost:5000/index.html
- Build the Docker image
./build.sh