c# - 如何在使用 .com 部署在 IIS 中的 .Net Framework 4.7 项目中显示 swagger/ui/index 页面
问题描述
我有一个在 .NET Framework 4.7 中运行的 web api 项目。我添加了 Reference Swashbuckle.Core 来显示 swagger ui。我还更新了 .csproj 以添加文档 .xml 文件。当我使用 url http://localhost:55677/swagger/ui/index运行我的应用程序时,它在我的开发机器上工作。但是当我使用 Visual Studio 发布应用程序时,它显示为“404 - 找不到文件或目录”。这可能是因为 UI 页面 Swaggerui 在已发布的 bin 文件夹中不可用。发布的 url 看起来像“ https://xxx.xxx.xxx.com ”。但是加载后我给了“ https://xxx.xxx.xxx.com/swagger/ui/index“显示招摇的用户界面。但它显示404错误。我没有使用任何.net核心项目。只是.net框架。
有人请帮我解决这个问题。
在查看了几个站点后,我在 SwaggerConfig.cs 文件中添加了这些代码部分。
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "App Name");
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory + "bin\\", xmlFile);
c.IncludeXmlComments(xmlPath);
c.ApiKey(ConfigurationManager.AppSettings.Get("apikey"))
.Description("API Key Authentication")
.Name("key-name")
.In("header");
c.RootUrl(req =>
req.RequestUri.GetLeftPart(UriPartial.Authority) +
req.GetRequestContext().VirtualPathRoot.TrimEnd('/'));
})
.EnableSwaggerUi(c =>
{
c.EnableApiKeySupport("key-name", "header");
});
RootUrl 是我从网站上找到的重定向到 SwaggerUI 页面的那个。但它不起作用。
解决方案
推荐阅读
- python - 如何解决我的 python 代码(数组和绘图)中的问题?
- firebase - 使用 FirebaseAuth 在我的颤振应用程序中重置密码
- sql - 在 PgAdmin 4 实用程序中找不到
- c++ - 这个类是否满足分配器的要求?
- javascript - 在 ReactJS 中获取和缓存图像
- java - 为什么我在 VS Code 中找不到 Java 类路径错误
- sql - Sequelize:如果至少有一项匹配,则忽略所有行
- dataframe - 熊猫 str 分裂。我可以跳过会带来麻烦的线路吗?
- xml - 使用 SOAPCore 访问 XML 标头
- php - cron php 作业无法在 Mac OS 中打开网络挂载卷上的文件