[ASP. NET Core] Getting Started, coregetting

Source: Internet
Author: User

[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
  • After the development work is completed, the developer can open the browser and enter the URL "http: // localhost: 5000" to go to the browser, you can see the "Hello World! ".

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.