Where to store the JSON file which will be referenced for the environment variable in asp.net hosted on Azure

纵饮孤独 提交于 2021-02-19 02:39:43

问题


I have created a Web Service using ASP.NET and will be storing data in Firestore. Hence, I will need to set the GOOGLE_APPLICATION_CREDENTIALS environment variable referring to a JSON file. This works locally on my machine, but it doesn't work when it's published to Azure. The problem is I couldn't find the JSON file to locate the file path, I have double checked my local project folder whether the JSON file is in there before publishing. May I know where is the best place to store my JSON file, so that I can locate the file path and GOOGLE_APPLICATION_CREDENTIALS can refer to it in the Azure Portal.

Thank you.


回答1:


If your json file is in project when publishing it, it will be uploaded to D:\home\site\wwwroot\xxx.json. You could go to https://yourwebname.scm.azurewebsites.net to find it.

So, you could set the environment variable in Application settings on portal as below:




回答2:


Here's another alternative if you're looking to avoid having that credential file checked into source control or on dev machines, and you already have a secure place to store string configuration data.

You can spin up your Firestore client this way and give it credentials manually:

 var credential = GoogleCredential.FromJson(<JSON AS STRING>);
 var channelCredentials = credential.ToChannelCredentials();
 var channel = new Channel(FirestoreClient.DefaultEndpoint.ToString(), channelCredentials);
 var client = FirestoreClient.Create(channel);

(Code using the Nuget package here: https://www.nuget.org/packages/Google.Cloud.Firestore/)



来源:https://stackoverflow.com/questions/53821909/where-to-store-the-json-file-which-will-be-referenced-for-the-environment-variab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!