From entry to abandonment of webapi (1) OWIN self-hosting mode

 1. Create an empty web project

 

2. After creating the picture

 

3. Install the following packages
Microsoft.AspNet.WebApi.Core (5.2.4)
Microsoft.Owin.Host.SystemWeb (4.0.0)
Microsoft.AspNet.WebApi.Owin (5.2.4)

 

4. Add a folder named "Contollers" in the project, and add an empty webapi controller as shown in the figure


5. Add the Startup class and the WebApiConfig class, as shown in the figure

   public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            HttpConfiguration httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            appBuilder.UseWebApi(httpConfiguration);
        }
    }
   public class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
               name: "DefaultApi",
               routeTemplate: "{controller}/{action}/{id}",
               defaults: new { id = RouteParameter.Optional }
           );
        }
    }

 

6. Run the website, enter the configured routing address, and the test passes.

 

 

Reference link:

https://dotnetcodr.com/2015/07/02/building-a-web-api-2-project-from-scratch-using-owinkatana-net-part-1/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325174291&siteId=291194637