ASP. NET Web API----instance

Source: Internet
Author: User

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.

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.