gpt4 book ai didi

asp.net-web-api2 - 如何将 web.config 添加到 owin 自托管 web api?

转载 作者:行者123 更新时间:2023-12-04 01:47:38 24 4
gpt4 key购买 nike

我实际上只是创建了一个 NServiceBus 自托管端点,并通过添加 Microsoft.AspNet.WebApi.OwinSelfHost nuget 包来引导 owin 自托管 Web API 2。一切都正常运行,我可以访问我添加的 Controller 端点,但程序包没有添加像 web.config 这样的正常项目。

我想让普通的 web.config 可用到我还可以添加不同构建配置的地方(转换文件,如 web.debug.configweb.release.config 等)。

如何将它添加到我的项目中?

我尝试只添加文件,但 ConfigurationManager 没有读取它。

最佳答案

web.config 用于托管服务器上的 asp.net web 应用程序。由于您使用的是自托管服务器,因此 web.config 不适用。您将需要 app.config,它将解析为具有 .config 文件扩展名的可执行文件名称。

app.config 添加到项目中,ConfigurationManager 应该可以读取它。

更新:

有人指出 app.config

也需要相同的配置转换

以下 VS 工具填补了 web.config 转换之间留下的空白。

Configuration Transform

Automatically transform app.config or any other config during build process. Once the transformation is set, it will run on other build machines without the extension.

该链接包含有关如何在应用配置转换时使用它的分步说明。

关于asp.net-web-api2 - 如何将 web.config 添加到 owin 自托管 web api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42546518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com