[ASP. NET Core] Getting Started, coregetting
[ASP. NET Core] Getting Started Preface
This article describes how to quickly create an ASP. NET Core application and keep a record for yourself, hoping to help developers who need it.
- ASP. NET Core Official Website
Environment
To create an ASP. NET Core application, you must first download the SDK from the official website to build the. NET Core development environment.
. NET Core official website
Download the. NET Core SDK according to the operating system.
Install. NET Core SDK
After the. NET Core SDK is installed, enable the command prompt character. Enter "dotnet" and the system responds to the. NET Core information normally. This completes the establishment of the. NET Core development environment.
Development
After the development environment is built, you can write ASP. NET Core applications. Create a new folder named "lab 」.
Add a file named "project. json" to the lab folder 」. Modify the file content to the following json format to set the project parameters of the ASP. NET Core application.
{ "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": {}, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" }, "imports": "dnxcore50" } }}
Then, add a file "Program. cs" to the lab folder 」. Modify the file content to the following C # program code, which is used as an example program for ASP. NET Core applications.
Using System; using System. threading. tasks; using Microsoft. aspNetCore. http; using Microsoft. aspNetCore. hosting; using Microsoft. aspNetCore. builder; namespace aspnetcoreapp {public class Program {public static void Main (string [] args) {// Build var host = new WebHostBuilder () // set the startup parameter. useStartup <Startup> () // enable Kestrel to listen to HTTP. useKestrel () // sets the URL of the listener. useUrls (" http://localhost:5000 ") // Create a Host. build (); // Run try {// start Host host. start (); // wait for the Console to be closed. writeLine ("Application started. press any key to shut down. "); Console. readKey ();} finally {// close Host host. dispose () ;}} public class Startup {// Methods public void Configure (IApplicationBuilder app) {// mount the custom Middleware app. useMiddleware <HelloWorldMiddleware> () ;}} public class HelloWorldMiddleware {// Fields pri Vate readonly RequestDelegate _ next; // Constructors public HelloWorldMiddleware (RequestDelegate next) {_ next = next;} // Methods public Task Invoke (HttpContext context) {return context. response. writeAsync ("Hello World! ");}}}
Start the command prompt character and enter the above lab folder. Enter dotnet restore to initialize the ASP. NET Core application.
After initializing the ASP. NET Core application, enter "dotnet run" to compile and execute the ASP. NET Core application.
Run
Reference
ASP. NET Core Getting Started-ASP. NET
ASP. NET Core 1.0 Hello World-Xiao Zhu®Technology with handwriting
Middleware-ASP. NET Core information sharing of ASP. NET Core