1. Open the NuGet package
2. Install the following two packages
3. After the installation, the SwaggerConfig.cs class will appear, and the contents of the content can be modified.
Code:
[Assembly:preapplicationstartmethod (typeof (Swaggerconfig), "Register")]namespace webapplication1{public Class Swaggerconfig {public static void Register () { var thisassembly = typeof (Swaggerconfig). Assembly; Globalconfiguration.configuration . Enableswagger (c + = { c.singleapiversion ("v1", "WebApp"); }) . Enableswaggerui (c + = { getxmlcommentspath (); }); } private static string Getxmlcommentspath () { return [email protected] ' { System.appdomain.currentdomain.basedirectory}\bin\webapi.xml "; }}
4. Add WebApi.cs Class
Code:
namespace webapi{public static class Webapiconfig {public static void Register (Httpconfiguration config) { //Web API Configuration and Services //Web API Routes CONFIG. Maphttpattributeroutes (); Config. Routes.maphttproute ( name: "DefaultApi1", routetemplate: "Api/{controller}/{action}/{id}", defaults : new {id = routeparameter.optional} ); Config. Routes.maphttproute ( name: "DefaultApi2", routetemplate: "Api/{controller}/{action}/{id}", defaults:new {action= "get", id = routeparameter.optional} );}}}
5. Modify the Global.asax class
Code:
public class MvcApplication:System.Web.HttpApplication { protected void Application_Start () { Arearegistration.registerallareas (); Routeconfig.registerroutes (routetable.routes); Globalconfiguration.configure (webapiconfig.register); This is to be added } }
6. Set the class to be debugged
7. Set up the generated XML document
8. Run the project and open the browser input http://localhost:23092/swagger/
Results show:
Very useful API Management--sawgger