简体   繁体   中英

Add existing WEB.API project to NopCommerce

I have an existing WEB API 2 project with JWT authentication. how I merge my WEB API application so it's similar like Administration project. the route will be something like localhost/api/[myApiRoute] I know there's an alternative way using plugin, but I got a dead end implementing JWT and my customization handler.

So I ended up by adding a Web API to NOP.WEB project.

The steps I needed to perform were:

  1. Add Web API Packages ( How to add Web API to an existing ASP.NET MVC 4 Web Application project? )
  2. Add OWIN Packages ( http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/ )
  3. Configure the Startup.cs

now you can use [System.Web.Http.Authorize] attribute to authorize your API using OWIN Authentication. I also add new folder called API and put all API files there (Controller, Models, Provider, Handlers, etc.) so it would easy to maintain.

For API routing, I'm using Attribute Routing ( http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2 ). you can add config.MapHttpAttributeRoutes() at Startup.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM