C#.net MVC,设置Google Application Credentials JSON文件的路径

Ste*_*ang 11 c# json credentials

我刚刚将这个Google Sample Project用于我的VS2015,

但是,在我发布到"IIS"并托管它之后,当我打开链接时,网页会一直显示此消息,如图所示

错误图片

我在web.config中添加了密钥,但仍然无法正常工作,只是想知道是否有人之前已经这样做了,我真的需要帮助,谢谢!

编辑:这是我的代码

Web.Config中

  <appSettings>
<!-- Set to your Google project id as shown on the Google Developers Console -->
<add key="GoogleCloudSamples:ProjectId" value="gdtest-1332" />
<add key="GOOGLE_APPLICATION_CREDENTIALS" value="D:\ProjectCloud\gdtest-12323.json" />
<!--
Set to either mysql or datastore.
If using mysql, update the connectionString far below, and then run Update-Database in the
Package Manager Console.
-->
<add key="GoogleCloudSamples:BookStore" value="datastore" />
<!-- Set to your Google Cloud Storage bucket -->
<add key="GoogleCloudSamples:BucketName" value="cloudstoragetestbillez" />
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
Run Code Online (Sandbox Code Playgroud)

小智 19

以编程方式在运行时设置环境变量:

string credential_path = @"C:\..\key.json";
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);
Run Code Online (Sandbox Code Playgroud)

我不是IIS的专家,但它似乎不会在桌面环境中设置环境变量.


小智 -1

从谷歌文档来看,它似乎是 env var 而不是 web.config。

如果您使用服务帐户凭据,请将环境变量 GOOGLE_APPLICATION_CREDENTIALS 设置为您下载的 JSON 凭据文件的路径。