Access management system for ASP. NET Core Project (0) Out of nowhere

Source: Internet
Author: User

0 Preface

Http://www.cnblogs.com/fonour/p/5848933.html

The best way to learn is to do it, and here to develop an ordinary access management system to experience and learn ASP. NET Core from zero. The overall planning of the project is broadly as follows:

Technical Route

    • ASP. NET Core MVC
    • Entityframeworkcore
    • Bootstrap Adminlte
    • PostgreSQL

Implementation features

    • Management of organizational structures
    • Role management
    • User Management
    • Functional management
    • Rights Management
1 Development Environment Preparation

1, install Visual Studio 2015, I installed here is the professional version.

2. Install. NET Core SDK-related

You need to install Visual Studio update3 and net Core 1.0.0-vs tooling

2 New Project

Open Visual Studio 2015, select the Project save path, enter the project name and solution name, and create a new ASP. Net Core Web application (. Net core) project.

To better understand some of the ASP. I chose the empty template here

Creating a good project is what it looks like.

General description of the relevant files in the solution

    • Wwwroot storing static resources such as Js,css,images
    • Program.cs Application Portal
    • Startup.cs application-related startup item configuration, which contains the configureservices and configure two methods that are responsible for the configuration of the service, which is responsible for the configuration of the HTTP request pipeline.
    • Project.json the project's underlying configuration file

Delete The example page project_readme.html, at this time we directly F5 run the program, interface output HelloWorld, this is because Stratup.cs

        publicvoid  Configure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory Loggerfactory)        {            loggerfactory.addconsole ();             if (env. Isdevelopment ())            {                app. Usedeveloperexceptionpage ();            }            App. Run (async (context) =            {                await context. Response.writeasync ("Hello world! " );            });        }
3 MVC Basic App 3.0 add MVC Dependency Reference

There are two ways to add MVC references.

1 by Project.json

Open the Project.json file, add the MICROSOFT.ASPNETCORE.MVC reference in the Dependencies department, and when you type, Visual studio will have automatic hints, very intimate and convenient.

"Dependencies": {    "Microsoft.NETCore.App": {"      version": "1.0.0",      "type": "Platform"    },    " Microsoft.AspNetCore.Diagnostics ":" 1.0.0 ",        " Microsoft.AspNetCore.Server.IISIntegration ":" 1.0.0 ",    " Microsoft.AspNetCore.Server.Kestrel ":" 1.0.0 ",    " Microsoft.Extensions.Logging.Console ":" 1.0.0 ",    " MICROSOFT.ASPNETCORE.MVC ":" 1.0.0 "  },

2 through NuGet

Search MICROSOFT.ASPNETCORE.MVC Add references through the NuGet Manager, or enter the command directly in the Package Manager console Install-Packages Microsoft . Aspnetcore. MVC can complete the addition of MVC references.

3.1 Adding a Controller

Right-click Add Project folder, name controllers, right-click Controllers folder, add a controller named HomeController.

3.2 Adding views

Right-click the project to add Views folder, right-click on the View folder to add a home folder, corresponding to the HomeController controller, in the home folder, a new name named index of the file.

Change the contents of index.cshtml to

< H1 > Hello,asp.net Core MVC</H1>
3.3 Adding MVC service and HTTP request pipeline processing

1 Adding an MVC service

The Configureservices method for modifying Startup.cs is as follows

        publicvoid  configureservices (iservicecollection services)        {            services. Addmvc ();        }

2 adding HTTP request pipeline Processing

The Configure method for modifying Startup.cs is as follows

  public  void   Configure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory loggerfactory) {loggerfact Ory.            Addconsole ();  if   // app.            Run (Async (context) =  // {  //  await context.            Response.writeasync ("Hello world!");         //  }

F5 running the program, you can see that you can already follow the MVC default routing mechanism parsing.

4 ASP. NET core default two boarding methods

The ASP. NET core application provides both the IIS service and the Kestrel service by default, which means that the ASP. NET core application can run out of IIS, which is also a cross-platform basis. You can see the addition of this service in the Program.cs file.

        publicstaticvoid Main (string[] args)        {            var New Webhostbuilder ()                . Usekestrel ()                . Usecontentroot (Directory.GetCurrentDirectory ())                . Useiisintegration ()                . Usestartup<Startup>()                . Build ();            Host. Run ();        }

The default startup options for Visual Studio are IIS Express, which means that we can use the Kestrel service to run our programs in the following two ways, using the IIS service mode.

1 Select the option of our project name in the startup option of VS, then run F5.

2 at the root of the project folder, hold down the SHIFT key, right-click the "Open Command Window Here" menu and enter the dotnet Run command.

will prompt the application service has started, and the address is http://localhost:5000, we open the browser to enter this address, you can see the page output of our expected results, and the use of the IIS service is the same effect.

You can modify the address of the application in Program.cs by using the Useurls method.

        publicstaticvoid Main (string[] args)        {            var New Webhostbuilder ()                . Usekestrel ()                . Useurls ("http://localhost:8000")                . Usecontentroot (Directory.GetCurrentDirectory ())                . Useiisintegration ()                . Usestartup<Startup>()                . Build ();            Host. Run ();        }

Access management system for ASP. NET Core Project (0) Out of nowhere

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.