首页 > 解决方案 > Azure Web App 和 .NetCore WebAPI - 缺少 web.config

问题描述

据我了解,.NetCore 不再使用/需要 web.config——而是选择 appsettings.json。

我有一个尝试在 Azure WebApp 中托管的 .NetCore WebAPI。我已将 API 发布到 WebApp,但我不断收到 500 错误。查看应用程序日志,我可以看到错误是:

IIS was not able to access the web.config file for the web site or application.

我很困惑。如果 .NetCore 使用 appsettings.json 而不是 web.config 并且如果没有 web.config,Azure 将无法工作,那么应该如何在 Azure 中托管 .NetCore 应用程序?

更新

我现在意识到这与 web.config 无关,这要感谢@joey-cai 为我指明了正确的方向。

Azure 似乎不喜欢我在连接字符串中使用 Azure Active Directory 身份验证的尝试。我将连接字符串更改为简单地使用 SQL 身份验证,一切正常。所以我想我现在的问题是,我如何为我的连接字符串使用 AAD 身份验证而不是 SQL 身份验证。

这个 SO 线程似乎表明我的连接字符串确实为 AAD 身份验证正确设置,但我收到错误:

Keyword not supported: 'authentication' 

每当我像这样使用连接字符串时:

Server=tcp:dbname.database.windows.net,1433;Initial Catalog=dbnamesqldb;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Password";

由于问题现在已经改变,我将使用新问题创建一个新帖子

标签: azureasp.net-coreazure-web-app-service

解决方案


这是否意味着我必须拥有 we.config?如果是这样,它可以只是一个空文件吗?

当您将 .net 核心项目部署到 Azure 时,您可以转到https://xxxxx.scm.azurewebsites.net并单击Debug console> CMD > site > wwwroot > web.config.web.config在那里。

尝试在 azure 中删除该站点并在 azure 中重新创建该站点。此外,尝试通过运行dotnet MyApp.dll并确保其正常运行来运行您正在部署的应用程序。您需要更多详细信息来了解为什么它会出现应用程序问题。这可能会有所帮助。还可以考虑使用自包含应用程序进行测试。还可以尝试在 azure app 服务上安装asp.net 核心扩展。

有关详细信息,您可以参考将ASP.NET Core 应用部署到 Azure 应用服务


推荐阅读