简体   繁体   中英

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. 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.

In my Startup class in Configureservices method in am reading app settings with Configuration["Appsettings:Authorization"]. On my local machine this value is coming from 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 应用程序设置

To troubleshoot it I redeployed the application to Azure now but included appsettings.json and it now the app is working fine.

I would like to know if Configuration["Appsettings:Authorization"] is right way to read Azure App settings or I am doing something wrong here. 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.

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. 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.

(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.

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.

step 2 - setup another web app, like a test web app or a staging web app or something, give it a go again. I believe, when you are configuring the app with the appsetting values, you are making a mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM