asp.net-web-api – Web API帮助页面和API Explorer返回0描述
我有这个项目只是一个Web API项目.在过去的某个时候,我删除了HelpPages,我让应用程序使用了OWIN.
现在我被要求添加API HelpPages,我已经完成了. 我已将我的Startup类设置为看起来像这样: public void Configuration(IAppBuilder app) { // Needs to be first app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); // For more information on how to configure your application,visit http://go.microsoft.com/fwlink/?LinkID=316888 var httpConfig = new HttpConfiguration(); // Register all areas AreaRegistration.RegisterAllAreas(); ConfigureOAuthTokenGeneration(app); ConfigureOAuthTokenConsumption(app); ConfigureWebApi(httpConfig); app.UseWebApi(httpConfig); } 这样我的帮助页面的路线就可以了. 在我的ConfigureWebApi方法中,我删除了格式,我已经注释了但仍然无效,这里是方法: private void ConfigureWebApi(HttpConfiguration config) { // Web API configuration and services var formatters = config.Formatters; var jsonFormatter = formatters.JsonFormatter; var serializerSettings = jsonFormatter.SerializerSettings; // Remove XML formatting formatters.Remove(config.Formatters.XmlFormatter); jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json")); jsonFormatter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local; // Configure our JSON output serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); serializerSettings.Formatting = Formatting.Indented; serializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; serializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None; // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi",routeTemplate: "api/{controller}/{id}",defaults: new { id = RouteParameter.Optional } ); } 我实际上编辑了HelpController并在返回视图行上放置了一个断点,这就是我知道ApiExplorer没有描述的方式: public ActionResult Index() { var docProdivder = Configuration.Services.GetDocumentationProvider(); var desciptions = Configuration.Services.GetApiExplorer().ApiDescriptions; ViewBag.DocumentationProvider = docProdivder; return View(desciptions); } 我在某处读到如果我这样做: public void Configuration(IAppBuilder app) { // Needs to be first app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); // For more information on how to configure your application,visit http://go.microsoft.com/fwlink/?LinkID=316888 var httpConfig = new HttpConfiguration(); var exploerer = new ApiExplorer(httpConfig); var descriptions = exploerer.ApiDescriptions; // Register all areas AreaRegistration.RegisterAllAreas(); ConfigureOAuthTokenGeneration(app); ConfigureOAuthTokenConsumption(app); ConfigureWebApi(httpConfig); app.UseWebApi(httpConfig); } 我应该看到描述,但它仍然无效. <member name="T:Melanite.Controllers.CollectionsController"> <summary> Controller for all collection related functions </summary> </member> <member name="M:Melanite.Controllers.CollectionsController.#ctor"> <summary> Default constructor </summary> </member> <member name="M:Melanite.Controllers.CollectionsController.Get(System.Int32)"> <summary> Get all the collections for the given center </summary> <param name="centerId">The id of the center that the collection belongs to</param> <returns>A list of collections</returns> </member> <member name="M:Melanite.Controllers.CollectionsController.Get(System.Int32,System.DateTime)"> <summary> Get all the collections for the given center on a specific date </summary> <param name="centerId">The id of the center that the collection belongs to</param> <param name="date">The planned collection date for the collections</param> <returns>A list of collections</returns> </member> 我在HelpPageConfig中取消注释了这样的行: // Uncomment the following to use the documentation from XML documentation file. config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); 并确保XML文件位于App_Data文件夹中.这些名字都是正确的,但是当我运行我的项目时,我仍然没有得到ApiExplorer的描述. 所以,你可以看到我在我的智慧结束.我希望有人之前遇到过这个并且知道如何修复它.如果你这样做,请帮忙! 解决方法
我也有同样的问题.如果我加了
在Startup类(我不使用global.asax)一切正常.我希望这对你也有帮助. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 为什么ASP.NET MVC忽略了我的尾随斜杠?
- 为什么ASP.NET框架在响应中添加“X-Powered-By:ASP.NET”H
- asp.net – .NET 4.0实现OutputCacheProvider
- asp.net-mvc-4 – ASP.NET MVC4自定义路由
- asp.net-mvc – 在我自己的OWIN中间件中使用Ninject DI
- asp.net-mvc-2 – 是asp.net MVC2包括在.net 4.0框架?
- 将ASP.NET ConnectionString设置为特定的域用户
- 如何:在ASP.NET自定义服务器控件中使用AJAX
- asp.net – 如何在设计模式下打开RDLC
- bytearray图像asp.net
- asp.net – 来自AJAX的表单身份验证和POST请求
- 按代码更改ASP.NET成员资格提供程序
- asp.net-core – 无法从Client访问IdentityServe
- asp.net-mvc-3 – 具有角色的AuthorizeAttribute
- asp.net-mvc – OAuth 2 Google API刷新令牌为空
- asp.net-mvc-4 – 如何在MVC4 ViewModel,Control
- Asp.Net Core中WebSocket绑定的方法详解
- ASP.NET MVC3 – 您如何处理探测请求?
- ASP.NET MVC中QueryString拼接更新
- asp.net-mvc-3 – 如何在Entity Framework中更新