Asp. Net Core project practices-permission management system (0) out of nothing, core permission management system

Source: Internet
Author: User

Asp. Net Core project practices-permission management system (0) out of nothing, core permission management system

0 Asp. Net Core: permission management system (0)

1 Asp. Net Core project practice-permission management system (1) Use AdminLTE to build a front-end

2 Asp. Net Core project practice-permission management system (2) function and entity Design

3. Asp. Net Core: permission management system (3) using PostgreSQL through EntityFramework Core

4 Asp. Net Core project practices-permission management system (4) multi-project hierarchical implementation of dependency injection, warehousing, and services

5 Asp. Net Core project practices-permission management system (5) User Logon

6 Asp. Net Core project practice-permission management system (6) function Management

7 Asp. Net Core project practice permission management system (7) Organization Management

Github Source Code address

0 Preface

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

The best way to learn is to do it. Here we will develop a general permission management system to experience and learn Asp.net Core from scratch. The overall project planning is roughly as follows:

Technical Route

  • Asp.net Core Mvc
  • EntityFrameworkCore
  • Bootstrap AdminLTE
  • PostgreSQL

Implement Functions

  • Organization Management
  • Role management
  • User Management
  • Function Management
  • Permission management
1. Prepare the development environment

1. Install Visual Studio 2015. I have installed the Professional Edition here.

2. Install. NET Core SDK

Installation requiredVisual Studio 2015 update3 and NET Core 1.0.0-VS 2015 Tooling

2. Create a project

Open Visual Studio 2015, select the SAVE project path, enter the project name and solution name, and create an Asp. Net Core Web Application (. NET Core) project.

To better understand some things of Asp.net Core, I chose an empty template here.

The created project looks like this.

General description of related files in the solution

  • Wwwroot stores js, css, images, and other static Resources
  • Program. cs application portal
  • Startup. cs application Startup Item configuration, including ConfigureServices and Configure. The former is responsible for service configuration, and the latter is responsible for http request pipeline configuration.
  • Basic configuration file of project. json project

Delete project_readme.html from the example Page. At this time, we directly run the program F5 and output HelloWorld on the interface, because in Stratup. cs

        public void 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. Basic Mvc application 3.0 add MVC dependency reference

There are two methods to add MVC references.

1. Use project. json

Open the project. json file and add a reference to Microsoft. AspNetCore. Mvc in the dependencies department. When you enter the file, Visual Studio will automatically prompt you, which is very considerate 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 for Microsoft. AspNetCore. Mvc to add a reference using the NuGet manager, or directly enter the command in the Package Manager Console.Install-Package Microsoft.AspNetCore.MvcYou can add the Mvc reference.

3.1 Add a controller

Right-click the project folder, name it Controllers, right-click the Controllers folder, and add a controller named HomeController.

3.2 Add a view

Right-click the project to add the Views folder, right-click the Views folder to add a Home folder, corresponding to the HomeController controller, and create a View File named Index under the Home folder.

Modify the content of Index. cshtml

3.3 Add the MVC service and Http request Pipeline

1. Add the MVC Service

The method for modifying ConfigureServices of Startup. cs is as follows:

        public void ConfigureServices(IServiceCollection services)        {            services.AddMvc();        }

2. Add an Http request Pipeline

The Configure method for modifying Startup. cs is as follows:

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)        {            loggerFactory.AddConsole();            if (env.IsDevelopment())            {                app.UseDeveloperExceptionPage();            }            app.UseMvcWithDefaultRoute();            //app.Run(async (context) =>            //{            //    await context.Response.WriteAsync("Hello World!");            //});        }

When F5 runs the program, you can see that it can be parsed according to the default Routing Mechanism of mvc.

4 Asp. Net Core default two boarding Methods

By default, Asp. Net Core applications provide two boarding Methods: IIS service and Kestrel service. This means that Asp. Net Core applications can run without IIS, which is also the basis of cross-platform. You can see the addition of this service in the Program. cs file.

        public static void Main(string[] args)        {            var host = new WebHostBuilder()                .UseKestrel()                .UseContentRoot(Directory.GetCurrentDirectory())                .UseIISIntegration()                .UseStartup<Startup>()                .Build();            host.Run();        }

The default startup option of Visual Studio is IIS Express, which adopts the IIS service mode. We can run our program using the Kestrel service in the following two ways:

1. select the option with the same name in the startup option of VS and run F5.

2. In the root directory of the project folder, press the Shift key, right-click, click the "open command window here" menu, and enter the dotnet run Command.

The system will prompt that the application service has been started and the address is http: // localhost: 5000. Open the browser and enter this address. The expected result is displayed on the page, the same effect as using the IIS service.

You can use UseUrls to modify the application address in Program. cs.

        public static void Main(string[] args)        {            var host = new WebHostBuilder()                .UseKestrel()                .UseUrls("http://localhost:8000")                .UseContentRoot(Directory.GetCurrentDirectory())                .UseIISIntegration()                .UseStartup<Startup>()                .Build();            host.Run();        }

Reference page:

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-setup-entityframework.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-dbcontext.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-razor-layout.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-view-start.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-import-view.html

It learning materials

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.