Create a WEBAPI project that uses Owin to host based on an empty project template

Source: Internet
Author: User

Start by creating an empty Web project, as shown in:

After the project is successfully created, install the following three package.

Install-package Microsoft.aspnet.webapi-version 5.2.2
Install-package Microsoft.aspnet.webapi.owin-version 5.2.2
Install-package Microsoft.owin.host.systemweb-version 3.0.0

Create Owin Startup class

1 usingSystem;2 usingSystem.Threading.Tasks;3 usingMicrosoft.owin;4 usingOwin;5 usingSystem.Web.Http;6 7[Assembly:owinstartup (typeof(Firstowinwebapi.startup))]8 9 namespaceFirstowinwebapiTen { One      Public classStartup A     { -          Public voidConfiguration (Iappbuilder app) -         { thehttpconfiguration config =Newhttpconfiguration (); -  -             //Web API Routes - CONFIG. Maphttpattributeroutes (); +  -             //webapiconfig.register (config); +  A app. Usewebapi (config); at         } -     } -}


Create an API Controller.

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Net;5 usingSystem.Net.Http;6 usingSystem.Web.Http;7 8 namespacefirstowinwebapi.controllers9 {Ten[Routeprefix ("Api/helloworld")] One      Public classHelloworldcontroller:apicontroller A     { -[Route ("")] -          Publicihttpactionresult Post () the         { -  -             returnok<string> ("Hello World"); -  +         } -  +     } A}

F5 run, Access API using Postman

Some other Owin middleware packages:

Install-package Microsoft.aspnet.webapi-version 5.2.2

Install-package Microsoft.aspnet.webapi.owin-version 5.2.2

Install-package Microsoft.owin.host.systemweb-version 3.0.0

Install-package Microsoft.owin.cors-version 3.0.0

Install-package Microsoft.owin.security.oauth-version 3.0.0

Install-package Microsoft.owin.security.jwt-version 3.0.0

Install-package system.identitymodel.tokens.jwt-version 4.0.0

Install-package Thinktecture.IdentityModel.Core Version 1.2.0

Install-package Microsoft.aspnet.identity.owin-version 2.0.1

Install-package Microsoft.aspnet.identity.entityframework-version 2.0.1

Create a WEBAPI project that uses Owin to host based on an empty project template

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.