ASP. NET Core Webapi Create project
Use VS to create a new project and select the ASP. NET Core Webapi.
At this point, the Configure and Configureservice methods of startup are as follows:
// HTTP请求管道public void Configure(IApplicationBuilder app, IHostingEnvironment env){ app.UseMvc();}// 配置IOC容器public void ConfigureServices(IServiceCollection services){ services.AddMvc();}
Configure Routing
WEBAPI uses the Restfull request method, for the controller, the route attribute is required to configure routing, and the action in the controller is configured with the HTTP feature.
[Route("api/[controller]")]public class TodoController : Controller{ }
The route configuration in the code above uses a wildcard character [controller] , which is equivalent to Todo .
Run the project
Ctrl+f5 run the project directly in VS, F5 to debug. Because WEBAPI does not have a Web page, it needs to be requested using postman.
Publish and deploy
The generated file contains all the DLLs and static resources that the program uses to launch the program at the command line after publishing to the directory.
dotnet DemoWebApi
Due to the cross-platform nature of. NET Core, post-release programs can run on all supported platforms.
ASP. NET core Kestrel is run as a Web server and can be used in conjunction with reverse proxy servers such as IIS, Apache, Nginx, and so on.
ASP. NET Core WebApi