WebApp Template and run
- ASP 1: Initialize and run the WebApp template
- Core Framework
- ASP. NET Core APP Create and run
- Summarize
The previous two articles briefly explain. NET core, and the relationship to the. NET Framework and the composition of. NET core, which are described in general. NET core, and then you plan to use a series to dissect the workings of ASP.
The ASP. NET Core is a new generation of ASP., which was earlier known as ASP. VNext, and was named as ASP. 5, but with the maturity of But it's a new generation of ASP. NET core functionality from scratch, so Microsoft announces that it will change it to the name of.
Operating on Windows platforms and non-Windows platforms such as Mac OSX and the Ubuntu Linux operating system, ASP. NET Core is Microsoft's first WEB development framework with a cross-platform capability.
Microsoft opened the ASP. NET Core at the outset, so it is also a member of the Open source project, managed by the (. NET Foundation).
The official version of. NET Core was released today (June 27, 2016), as Microsoft. NET Core 1.0 is officially released for download
Core Framework
With the development of. NET Core, the currently planned features are:
ASP. NET Core MVC: ASP. NET Core MVC provides APIs for developing dynamic Web sites, including webpages and WebAPI, which can eventually run on IIS or self-hosted (self-hosted) servers.
dependencyinjection: contains a generic dependency injection interface for use in ASP. NET Core mvc.
Entity Framework Core: Similar to the previous version of the EntityFramework version is a lightweight ORM framework that includes support for Linq,poco and Codefirst.
The ASP. NET core Identity: a framework for building user rights systems in the ASP. NET core Web applications, including functions such as membership, login and so on, which can be easily extended and customized.
ASP. NET Core APP Create and run
First, install the. NET Core SDK for Windows (Linux, MAC)
Take windows, for example, (),
After the installation is complete, you can dotnet -v view the version number with commands.
C:\Users\stephen>dotnet -vTelemetry is: Enabled.NET Command Line Tools (1.0.0-preview1-002702)Usage: dotnet [common-options] [command] [arguments]
Second, the command line to generate template project
Develop a webapp can create a file from scratch, or you can generate an empty project template from the command line, and the following code is used to create a template from scratch.
mkdir aspnetcoreappcd aspnetcoreappdotnet new
After executing the command sequentially, you can generate the template under the current path.
The template consists of the following three files:
Confederacy configuration settings for the project's run-time, including the project's package References, basic project settings, boot directives, include or exclude specified directories, and related event directives at construction time.
Program Entry File
Compared to Project.json, is the full reference list of the packages referenced in the Project.json file.
Third, modify the Project.json
Project.json is used to define the resources that the project needs to rely on, each webapp requires a hosting program (IIS, Iisexpress, and so on), and this Kestrel is used (what is Kestrel?), Add a list of dependencies for Kestrel in Project.json as follows.
"dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0-rc2-3002702" }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"},
Iv. Download the dependent Package deployment Web site
The WebApp deployment (dotnet Restore) relies on NuGet to download dependent packages based on the Project.json dependent files, completing the restore of the entire program. (NPM restore similar to Nodejs)
When C:\Users\stephen\.nuget\packages you can see that NuGet has been downloaded to a local package, NuGet does not load the dependent package before starting the deployment, and you can see that currently nuget does not download any packages.
Then execute the command.
restore
As you can see, NuGet has automatically downloaded the dependent packages to the local
V. Add Startup.cs file
is required for an ASP. NET Core program Startup Class . ASP. NET core will find the class named startup from assemblies when the program starts, and if there are multiple classes named Startup, the startup class under the project root namespace will be found first.
When startup must define a Configure method, and the method configureServices is optional, the method is invoked the first time the program is started, and the Routing and application State of a traditional ASP. NET MVC can be configured in startup, or you can install the required middleware here, and so on. Startup的详细功能的对于startup.cs中的configure和configureServices方法会在后续文章中详解.
Add the Startup.cs file under the file path just below and copy the following code:
Using System;Using Microsoft.Aspnetcore.Builder;Using Microsoft.Aspnetcore.Hosting;Using Microsoft.Aspnetcore.Http;Namespaceaspnetcoreapp{public < Span class= "Hljs-keyword" >class startup {< Span class= "Hljs-keyword" >public void configure (iapplicationbuilder app) {App.run (context = {return context.writeasync ( "Hello from ASP. core!");}); }}
VI. WEB Hosting Configuration
Copy the following code in the Program.cs file, specifying that the WebApp host program is Kestrel :
Using System;Using Microsoft.Aspnetcore.Hosting;Namespaceaspnetcoreapp{PublicClassprogram {Public static< Span class= "hljs-function" > void Main ( String[] args) { var host = new usekestrel (). usestartup<startup> (). build (); host. run ();} }}
VII. Compiling
dotnet build
After the code is complete, you need to call the Roslyn compiler to compile the code into assemblies and store it in the Bin folder. As described in the previous section (a brief analysis of the. NET Core composition System),
The ASP. NET Core App can be compiled into IL assemblies, and can also be compiled directly into machine code via native.
Eight, start
Enter Start command, Kestrel hosted Web program, and listen on port 5000, so the whole program starts up.
dotnet run
Summarize
This section describes the process of creating, configuring, compiling, publishing, and running an ASP. ASP. NET core is more transparent and flexible than the previous ASP, and can be developed and run quickly in various operating systems.
This section uses the Windows operating system, but Microsoft also linux mac provides similar command-line tools (link addresses) under and below, which are easy to develop and deploy in and out, which are linux mac explained in detail later in this section, which is no longer covered.
There are any errors or inaccuracies in the above content please correct me, do not like to spray!
The source of the handsome insects: http://www.cnblogs.com/vipyoumay/p/5620373.html
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility. If you feel that there is help, you can click on the lower right corner of the "recommendation", hoping to continue to bring good technical articles for everyone! Want to make progress with me? Then "pay attention" to me.
Reference links
"1" https://docs.asp.net/en/1.0.0-rc2/getting-started.html
Tags:. NET core, ASP.
WebApp Template and run