asp.net webapi 生成在线文档--Swagger

第一步:使用nuget包获取Swashbule、swagger.net.ui的包并安装。

安装成功后

打开App_Start->SwaggerNet.cs

注释掉一下两行

//[assembly: WebActivator.PreApplicationStartMethod(typeof(ApiInterface.App_Start.SwaggerNet), "PreStart")]
//[assembly: WebActivator.PostApplicationStartMethod(typeof(ApiInterface.App_Start.SwaggerNet), "PostStart")]

第二步

打开App_Start->SwaggerConfig.cs

增加一个GetXmlCommentsPath()的方法,具体内容如下:

private static string GetXmlCommentsPath()
{
  return string.Format("{0}/bin/ApiInterface.xml", System.AppDomain.CurrentDomain.BaseDirectory);
}

同时将此页面中“c.IncludeXmlComments(GetXmlCommentsPath());”去掉注释。

第三部

启用生成xml文档,右击项目文件属性

第四步

运行程序http://localhost:XXX/swagger/ui/index

显示界面:

原文地址:https://www.cnblogs.com/gskstudy/p/8329277.html