我有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)应用程序
有谁知道这可能是什么问题?
答案 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('/'));
}