简体   繁体   English

c# .Net Core 3.1 Azure App Service Windows - 应用程序无法检索应用程序设置

[英]c# .Net Core 3.1 Azure App Service Windows - Application not able to retrieve App settings

I am having issues with .Net core 3.1 app not behaving properly as the way it should.我遇到了 .Net core 3.1 应用程序无法正常运行的问题。 I can run the app fine on my local machine.我可以在本地机器上正常运行该应用程序。 I have added custom authorization on the app which runs fine on my local machine.我在我的本地机器上运行良好的应用程序上添加了自定义授权。 After i deploy the app into Azure App Service and use App Settings to configure the variables and restart the app and test it, authorization fails.在我将应用部署到 Azure 应用服务并使用应用设置配置变量并重新启动应用并对其进行测试后,授权失败。

In my Startup class in Configureservices method in am reading app settings with Configuration["Appsettings:Authorization"].在我使用 Configuration["Appsettings:Authorization"] 读取应用设置的 Configureservices 方法中的 Startup 类中。 On my local machine this value is coming from appsettings.json.在我的本地机器上,这个值来自 appsettings.json。 All good till.一切都好直到。

After I deploy the app to Azure, create app settings (please see screen shot)and restart the application and test, I get unAuthorize message.在我将应用程序部署到 Azure、创建应用程序设置(请参见屏幕截图)并重新启动应用程序并进行测试后,我收到了 unAuthorize 消息。 Azure 应用程序设置

To troubleshoot it I redeployed the application to Azure now but included appsettings.json and it now the app is working fine.为了解决它,我现在将应用程序重新部署到 Azure,但包含 appsettings.json,现在应用程序运行正常。

I would like to know if Configuration["Appsettings:Authorization"] is right way to read Azure App settings or I am doing something wrong here.我想知道 Configuration["Appsettings:Authorization"] 是否是读取 Azure 应用程序设置的正确方法,或者我在这里做错了什么。 Please advise.请指教。

Here is what I think.这是我的想法。

To troubleshoot it I redeployed the application to Azure now but included appsettings.json and it now the app is working fine.为了解决它,我现在将应用程序重新部署到 Azure,但包含 appsettings.json,现在应用程序运行正常。

This means, your app settings are fine, and the way you have deployed is also fine.这意味着,您的应用程序设置很好,您的部署方式也很好。 We can eliminate the possibility that something is wrong with the way you have deployed or setup the deployment.我们可以消除您部署或设置部署的方式出现问题的可能性。

I would like to know if Configuration["Appsettings:Authorization"] is right way to read Azure App settings or I am doing something wrong here.我想知道 Configuration["Appsettings:Authorization"] 是否是读取 Azure 应用程序设置的正确方法,或者我在这里做错了什么。 Please advise.请指教。

This is the correct way of doing it.这是正确的做法。 Also, the settings are being read fine (when you include appsettings.json) on both local running, and web app deployment.此外,本地运行和 Web 应用程序部署上的设置都可以正常读取(当您包含 appsettings.json 时)。

(for example, i have a auth app deployed here - https://github.com/Jay-study-nildana/APIServerDotNetCoreWithAuth0/blob/master/dotnetcoreapiserverwithauth0/Startup.cs ) which does the exact same thing you are doing. (例如,我在此处部署了一个身份验证应用程序 - https://github.com/Jay-study-nildana/APIServerDotNetCoreWithAuth0/blob/master/dotnetcoreapiserverwithauth0/Startup.cs )它与您正在做的完全相同。

how to solve?怎么解决?

step 1 - for now, if its really urgent, keep the appsettings.json in your main app, so that your customers/company is not affected.第 1 步 - 现在,如果真的很紧急,请将 appsettings.json 保留在您的主应用程序中,以免您的客户/公司受到影响。

step 2 - setup another web app, like a test web app or a staging web app or something, give it a go again.第 2 步 - 设置另一个 Web 应用程序,例如测试 Web 应用程序或暂存 Web 应用程序或其他东西,再试一次。 I believe, when you are configuring the app with the appsetting values, you are making a mistake.我相信,当您使用 appsetting 值配置应用程序时,您犯了一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 ASP.NET Core 3.1 配置 Azure App Service 应用程序设置? - How to configure Azure App Service application settings for ASP.NET Core 3.1? .NET Core 3.1 控制台应用作为 Windows 服务 - .NET Core 3.1 Console App as a Windows Service 如何在 c# .net core 3.1 控制台应用程序中保存设置? - how to save settings in c# .net core 3.1 console application? Writing Windows Service in C# .NET Core for Windows & Azure Cloud - Writing Windows Service in C# .NET Core for Windows & Azure Cloud .NET Core 3.1 控制台应用程序无法在 Windows 上运行 7 - .NET Core 3.1 Console App will not run on Windows 7 在 Azure 应用服务中的 ASP.NET Core 3.1 应用上调用 TryUpdateModelAsync 超时 - Timeout calling TryUpdateModelAsync on ASP.NET Core 3.1 app in Azure App Service C#App的应用程序设置 - Application Settings for C# App SoapAction header 不理解 - 使用 asmx web 服务 - 使用自定义绑定 - dot net core 3.1 c# 应用程序 - SoapAction header not understood - consuming a asmx web service - using custom binding - dot net core 3.1 c# app .NET核心Web API作为Azure应用程序服务上的虚拟应用程序 - .NET core web API as virtual application on Azure app service .NET Core C# 中的 Azure 应用服务容器托管标识密钥库 - Azure App Service Container Managed Identity Key Vault in.NET Core C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM