ASP.NET5 Practice 01:web Project creation, structure overview, program run, release deployment

Source: Internet
Author: User
Tags configuration settings web hosting windows 10 enterprise

1. Project Creation

There are three types of ASP.NET5 project templates:

New Project :

Select a template :

2. Structure overview

References corresponding configuration is in Project.json:

  " Frameworks " : {    "dnx451": {},    "dnxcore50" : { }  },

ASP.NET5 supports multiple versions of CLR coexistence at development time, but is used by the runtime.

Dnxcore50 is a cross-platform, modular coreclr. It has a variety of, such as: dnx-coreclr-win-*,dnx-coreclr-linux-* and so on.

The other is the full version, which only supports the Windows CLR.

There is, of course, a CLR with mono.

wwwroot is a static file store directory in a Web application and a root directory when the Web post is deployed.

where Web. config is the configuration file that is required for IIS deployment.

Because the ASP.NET5 Web program is the application of the MVC6 framework, the pipeline is: area/controller/action, not the actual file path.

So to use a static file, you need to reference the dependency: "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"

and open in Configure () in Startup.cs: App. Usestaticfiles ();

Bower and NPM in Dependencies are the front-end development tool plug-ins.

The usage profile for Bower is:

The NPM plug-in installation configuration file is:

Of course NPM plug-in uses need:

Right-click on the gulpfile.js to bring up the task:

Introduction to the front-end development tools, in later topics in detail.

The Controllers is the controller.

migrations is generated by the EntityFramework Manual add migration.

Models is a solid model class.

Services is a feature/Business implementation class.

ViewModels is a view model class.

views are view files.

Appsettings.json is a configuration file. For example, configure the database connection string.

Say the Startup.cs file, see the code Comment:

namespace MyWeb{ Public classStartup {/// <summary>        ///constructor Function/// </summary>        /// <param name= "env" >information about running applications in a web hosting environment</param>         PublicStartup (ihostingenvironment env) {//used in the build application to create an object based on the key/value configuration settings            varBuilder =NewConfigurationbuilder ()//Add the path to the JSON configuration provider to the Configurationbuilder. Addjsonfile ("Appsettings.json")                //Gets or sets the name of the environment to set this property automatically//If optional is fales, this setting is not required. . Addjsonfile ($"appsettings. {env. Environmentname}.json", Optional:true); //if the development environment            if(env. Isdevelopment ()) { //http://go.microsoft.com/fwlink/?LinkID=532709              Builder.            Addusersecrets (); }            //Add a configuration value to read the Iconfigurationprovider environment variableBuilder.            Addenvironmentvariables (); //generate iconfiguration keys and values//registering from the provider assembly in Iconfigurationbuilder.providersConfiguration =Builder.        Build (); }        /// <summary>        ///key/value application configuration root property, inheritance iconfiguration/// </summary>         PublicIconfigurationroot Configuration {Get;Set; } /// <summary>        ///This method is called when the program runs to add some services to the container/// </summary>        /// <param name= "Services" >Service Collection</param>         Public voidconfigureservices (iservicecollection services) {//ADD Framework Services.Services. Addentityframework (). Addsqlserver (). Adddbcontext<ApplicationDbContext> (options =options. Usesqlserver (
configuration["Data:DefaultConnection:ConnectionString"])); Services. Addidentity<applicationuser, identityrole>() . Addentityframeworkstores<ApplicationDbContext>() . Adddefaulttokenproviders (); Services. Addmvc (); //ADD application Services.
// using Dependency injection Services. Addtransient<iemailsender, authmessagesender>(); Services. AddTransient<ismssender, authmessagesender>(); } /// <summary> ///configuration, usually some middleware calls need to be configured, etc./// </summary> /// <param name= "app" >Configure the application's request pipeline</param> /// <param name= "env" ></param> /// <param name= "Loggerfactory" >Log Middleware</param> Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment env,
Iloggerfactory loggerfactory) {loggerfactory.addconsole (Configuration.getsection ("Logging")); Loggerfactory.adddebug (); if(env. Isdevelopment ()) {app. Usebrowserlink (); App. Usedeveloperexceptionpage (); App. Usedatabaseerrorpage (); } Else{app. Useexceptionhandler ("/home/error"); Try { using(varServicescope = App. ApplicationServices
. Getrequiredservice<iservicescopefactory>(). Createscope ()) {ServiceScope.ServiceProvider.GetService<ApplicationDbContext>() . Database.migrate (); } } Catch { } } //Middleware Module for IIS httpplatformhandler reverse proxy Server interactionApp. Useiisplatformhandler (options =options. Authenticationdescriptions.clear ()); App. Usestaticfiles (); App. Useidentity (); //Configure RoutingApp. USEMVC (routes ={routes. MapRoute (Name:"Arearoute", Template:"{area:exists}/{controller}/{action}", defaults:New{action ="Index" }); Routes. MapRoute (Name:"default", Template:"{controller=home}/{action=index}/{id?}"); Routes. MapRoute (Name:"API", Template:"{controller}/{id?}"); }); } //Entry point for the application. Public Static voidMain (string[] args) = webapplication.run<startup>(args); }}

3. Program operation

In VS2015 development, you can run directly with IIS Express, or you can choose to run the Web self-hosted host.

Of course, if you do not need to run VS2015, you can use the DNVM dnx.exe (execute file in the CLR) tool to execute.

The Dnx.exe Execution command is the commands configuration in the corresponding Project.json:

  " commands " : {    "web""Microsoft.AspNet.Server.Kestrel"  ,    "ef""entityframework.commands "   },

Go to DOS, see DNVM can use not?

After you create the ASP.NET5 program in VS2015, the DNVM is installed automatically.

Try again the Dnu and DNX tools:

Rattle! Not available. Then execute it:

Go to the directory where the Project.json file is located in the project and execute the DNX Web:

Ok! in the case of shut down, you can access it through http://localhost:5000.

Of course, if you publish, you can also directly execute the way Web.cmd run.

Note: If the run is unsuccessful.

Typically the dependent packages are not fully downloaded and can be installed using DNU restore.

The second is inconsistent with the framework used by the CLR and the Project.json configuration.

4. Release the deployment

You can use the Dnu Publish command to publish under DOS. This way the demo is a little bit.

On the project in the VS solution, right-click Publish Web:

Select File System ...

Published directory (three folders):

Enter the AppRoot directory, you can execute the web.cmd command script to run!

How is it usually deployed in IIS when it is actually produced? This is a test deployment using Windows 10 Enterprise IIS.

Install IIS First:

Just tick the Internet Information Services one!

Open the "Get new Web Platform components" in IIS Manager:

If it is not installed, install it first. Here I have installed the vs2015 when I update it.

Add-Install Httpplatformhandler.

To configure the editor, modify the section:

and unlock the section:

The preparation is almost complete! To add a Web site:

Note: The connection permissions setting, the application pool needs to be changed to unmanaged code!

Test:

5. Summary

The content of this chapter is very simple, I explain as much as possible! Hope Beginners can learn!

Project creation, the Fool will also;

Structure overview, here I can not say very clearly, very detailed.

The program runs, no matter how it works when it's not released, even after the deployment is released.

Publish the deployment, which describes how to publish on vs2015, and also says common IIS deployments.

Other ways to deploy, preferably Linux or OS system demo! Make up again later!

Readers can also refer to https://get.asp.net/ . Microsoft has always been a thoughtful little cotton-padded jacket, data and document collation is very good.

ASP.NET5 Practice 01:web Project creation, structure overview, program run, release deployment

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.