after the ASP. NET Web API----theoretical knowledge
Instance
VS2013 Create a new web API, such as:
The reference blog is to use the entity Framework Codefirst to create the database, which is the EF 6.X dbcontext generator.
This article is based on a database that already exists, create an ADO Entity Data model, such as:
Add a controller, such as:
There are several types of controllers that create controllers that inherit Apicontroller, such as:
Set up a corresponding class controller, and route the host to the web host. These code vs Auto-generated in Webapiconfig, as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using System; using System.Collections.Generic; using System.Linq; using System.Web.Http;
namespace WebApplication1 {
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name:
"DefaultApi"
,
routeTemplate:
"api/{controller}/{id}"
,
defaults:
new { id = RouteParameter.Optional }
);
}
} }
|
Use "Http://localhost:49719/api/{controller}/{id}" restful access.
The above is a simple ASP. NET Web API server instance.
There is also a self-host routing method that can be hosted directly on the website project.
The service side also has the security, the permission classification and so on, including the dependency injection and so on design pattern, can design very formidable.
I am also slowly study, hope to have the great God guidance.