Asp. Net Core project practices-permission management system (0) out of nothing, core permission management system
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.
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.
<H1> Hello, Asp. Net Core MVC
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.
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.
Public static void Main (string [] args) {var host = new WebHostBuilder (). useKestrel (). useUrls ("http: // localhost: 8000 "). useContentRoot (Directory. getCurrentDirectory ()). useIISIntegration (). useStartup <Startup> (). build (); host. run ();}