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