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

标签 c# json credentials

我刚刚获得了这个 Google 示例项目,可以在我的 VS2015 上运行,

但是我发布到“IIS”并托管后,当我打开链接时,网页一直显示如图所示的消息

Error Picture

我将 key 添加到 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" />

最佳答案

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

string credential_path = @"C:\..\key.json";
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

我不是 IIS 专家,但它似乎无法识别您桌面环境中设置的环境变量。

关于C# .net MVC,设置 Google Application Credentials JSON 文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37626200/

相关文章:

c# - 最优化使用多个 Where 语句

c# - GraphQL + Autofac

spring - 我应该在哪里存储 Spring Boot 项目的开发凭证?

powershell - 在Powershell中获取当前用户的凭据对象而不提示

c# - 如何在 C# ASP.NET MVC 5 中找到我们来自的 View (内置方式)?

c# - 无法从 gridview 内的 templateField 中的文本框获取值

java - 如何仅更改共享首选项中存储的 Json 对象中的一个值

php - Yii2 REST API 不返回预期结果

javascript - ExtJS 存储 - 只加载一次 JSON

amazon-web-services - 使用 groovy 脚本更新 jenkins 文件中的 aws 凭证