1、在VS2015中右键选择工程;

2、点击NuGet程序包;

3、输入Swagger在线搜索;

4、安装:Swagger.Net.UI和Swashbuckle包;

5、打开SwaggerNet.cs,注释掉:

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

5、右击WebAPI工程属性,切换到生成选项卡;

6、勾选输出:XML文档文件;

7、编译WebAPI工程文件;

8、配置文件Web.Config中添加:

<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

9、浏览器运行http://localhost:43287/swagger/,自动切换为:http://localhost:43287/swagger/ui/index

重要参考:

http://www.cnblogs.com/Leo_wl/p/5463839.html

备注:

SwaggerUI/index.html可能无效

建议新增一个index.htm页面,内容是:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script type="text/javascript">
window.top.location.href = "/swagger/";
</script>
</body>
</html>

最新文章

  1. 通用EF框架
  2. JS之模板技术(aui / artTemplate)
  3. selector 的用法,在选择和不选择情况下的颜色
  4. [Android]官网《Testing Support Library》中文翻译
  5. Java replace &amp; replaceAll
  6. good
  7. C#出题库项目的总结(2)
  8. POJ 1321棋盘问题
  9. ajax再接触
  10. Android增加监听的三种实现方式
  11. 9.Linux系统引导流程
  12. 财付通API
  13. spark与hive的集成
  14. [Swift]LeetCode986. 区间列表的交集 | Interval List Intersections
  15. sql左外连接和右外连接的区别例子转摘
  16. luogu1503
  17. ibatis的queyrForList和queryForMap区别
  18. Java 中的伪共享详解及解决方案
  19. JS实现用特殊符号替换字符串的中间部分区域
  20. django 单元测试错误总结

热门文章

  1. JavaHbase连接代码示例
  2. js+php实现文件上传显示文件上传进度条的插件
  3. 一款基于jquery带百分比的响应式进度加载条
  4. 百兆千兆网口100Base-TX/1000Base-T
  5. Java 中的异常和处理详解
  6. 关于Cocos Studio制作游戏资源
  7. TensorFlow基础笔记(14) 网络模型的保存与恢复_mnist数据实例
  8. C#NetRemoting双向通信
  9. map正序、逆序排序
  10. AOP(Aspect Oriented Programming),即面向切面编程