1:asp.net Mvc5+ef6+easyui Backend Management System (1)-webapi and unity are injected with unity in order to use our back-end BLL and DAL layers
2:asp.net Mvc5+ef6+easyui Backend Management System (2)-WEBAPI and Unity Injection-config file
3:asp.net Mvc5+ef6+easyui Backend Management System (3)-MVC WEBAPI user authentication (1)
4:asp.net Mvc5+ef6+easyui Backend Management System (4)-MVC WEBAPI user authentication (2)
In the past we talked about the basic validation of WEBAPI, but a novice often came to ask me the way I used
This time, let's analyze the usage of the code and how to debug it.
Webapi in some scenarios we will use, such as:
1. Docking various clients (mobile devices) 2. Build common HTTP MicroServices 3. Open Data 4. Single Sign-on ...
65 Code Download Password: 4BFB
This article mainly demonstrates several points: it is also the review and finishing of the past
- 1. Using Helppage Documentation
- 2.Postman Debugging the interface (the previous sample is too simple, this time add some parameters, so that beginners see more of these scenes)
- 3. Debug interface
1.HelpPage API Help Documentation
Our new WEBAPI integrates Microsoft's own Helppage, the API's documentation, which automatically generates a document after we've written the interface.
Configuration of Helppage, very simple, two-step
To set the output XML document for a project property
2. Open Areas-->helppage-->app_start-->helppageconfig.cs
Public Static void Register (httpconfiguration config) { ///Uncomment the following to use the documentation from XML documentation file. Config. Setdocumentationprovider (new Xmldocumentationprovider (HttpContext.Current.Server.MapPath (" ~/bin/apps.webapi.xml")));
Set the Register method on line, run address Localhost:1593/help to get the following result
As can be seen, each controller interface is listed, and according to the comments and parameters to generate documents, automatic
Click on the interface to see the parameters and how to request
2. Debugging with Postman
: https://www.getpostman.com/
Pastman is very easy to use, we will take the login interface to test
Open Postman, create a new request
OK, we've got token! Note that when you create a new request, you set the Get,post
3. Verify Permissions
Prior to the article, we are accessing the interface data through the token's Way + interface permissions
Open the SupperFilter.cs filter code
URL Get token var content = Actioncontext.request.properties[configpara.ms_httpcontext] AsHttpContextBase; var token =Content. Request.querystring[configpara.token]; if (!string. IsNullOrEmpty (token)) {//decrypts user ticket and verifies that the user name password matches//Controller,action,id in the context of the read request var routes = new routecollection (); Routeconfig.registerroutes (routes); Routedata Routedata = routes. Getroutedata (content); The controller action,id the zone is removed. String controller = ActionContext.ActionDescriptor.ControllerDescriptor.Controlle Rname; String action = actionContext.ActionDescriptor.ActionName;//url path string filePath = HttpContext.Current.Request.FilePath; Determine if token is valid if (! ) Loginusermanage.validateticket (token)) {handleunauthorizedrequest (actioncontext);}// Determine if the role group authorization (if you do not need to use role group authorization can comment out this method, so that the login user can access all interfaces) if (! ) Validdatepermission (token, controller, action, FilePath)) {handleunauthorizedrequest (actioncontext);}//already logged in, with permission Base. IsAuthorized (Actioncontext);
The filter reads tokens from the user and makes 2 logical validations.
1. Verify that token is valid
2. Verify that the interface has no permissions (get action by assigning permissions in the background) This operation is the same as our authorization interface.
(Note: If the comment is off, all login users can access all interfaces, uncontrolled, mainly see the business scenario bar)
4. Use token to get data from other interfaces
See the Syssamplecontroller class, this class and common MVC sample interface In fact there is no difference, after the BLL all is universal, so logic does not need to re-write! According to the 2nd get token, configure to Postman can obtain data
1. Enquiry
2. Create
3. Modifications
4. Get details
5. Delete
Thank you, from the source directly can be seen, and their own testing or configuration, without losing is an experience
ASP. NET Mvc5+ef6+easyui Backend Management system-about WEBAPI usage