Web API 2 swagger文档根路径

时间:2018-01-10 17:46:02

标签: c# asp.net-web-api2 swagger-ui

我有Web API 2并使用[Swashbuckle] [1]配置Swagger:

library(purrr)
library(dplyr)

marcel.data <- data.frame(questionnaire = c("self", "self", "peer", "peer"),
                      ID = c(1, 2, NA, NA),
                      REF = c("1234", "2345", NA, NA),
                      SERIAL = c(NA, NA, "1234", "2345"),
                      x = c(4, 6, NA, NA),
                      y = c(NA, NA, 8, 4))


new_id_data <- map_df(1:nrow(marcel.data), function(i){

 if(marcel.data[i, 1] == "peer") { # matching peer to Self
  serial <- unique(marcel.data[i, "SERIAL"])  

  new.id <- marcel.data %>%     # getting the needed ID
   filter(REF == serial & questionnaire == "self") %>%
   select(ID)

  marcel.data[i, "ID"] <- new.id  # adding the new ID to the old data

  marcel.data[i,] 

 } else
  (marcel.data[i,])

})

在本地运行时,一切正常,我可以看到带有api端点的swagger页面。现在,当我们将其部署到默认网站\ AAAA下的IIS中时,路径始终被解析为默认网站的根,而不是AAAA(WebAPI)应用程序 enter image description here

有谁知道这可能是什么问题?

1 个答案:

答案 0 :(得分:1)

来自here.

的回答

IIS中托管的OWIN - VirtualPathRoot处理不正确 当您在OWIN / SystemWeb之上托管Web API 2时,Swashbuckle默认无法正确解析VirtualPathRoot。

您必须在启动时在HttpConfiguration中显式设置VirtualPathRoot,或者执行此类自定义以修复自动发现:

httpConfiguration.EnableSwagger(c => 
{
    c.RootUrl(req =>
        req.RequestUri.GetLeftPart(UriPartial.Authority) +
        req.GetRequestContext().VirtualPathRoot.TrimEnd('/'));
}