13

I've just got this Google Sample Project to work on my VS2015,

However, after I published to "IIS" and host it, when I opened the link, the web page kept showing this message as the picture showed

Error Picture

I added the key to the web.config, but still doesn't work, just wondering if anyone had done this before, I really need help, thank you!

Edit: Here is my code

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" />

Fanjo Lama
  • 581
  • 3
  • 15
Steven Wang
  • 131
  • 1
  • 1
  • 6
  • It will be hard to answer your question with out having a relevant subset of your code. – tmthydvnprt Jun 04 '16 at 04:05
  • According to your error seems like credentials issue . you need to define your credentials to run this project log in to google developer account and get credential . might be it's help to you. – Pankaj Gupta Jun 04 '16 at 05:06
  • Yep, the error message says that I need to set the path to the json file, but I tried many ways and still didn't get it to work :( but I could run the application on my Visual Studio tho – Steven Wang Jun 04 '16 at 05:36

5 Answers5

27

Programmatically set an environment variable at runtime as such:

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

I'm not an expert with IIS but it won't seem to pick up on environment variable set in your desktop environment.

2

Restarting the Visual Studio 2017 did it for me for Console Application.

Console.WriteLine(System.Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));

Kunal B.
  • 543
  • 6
  • 22
  • 1
    Processes inherit a _copy_ of their parent's environment table at creation time. My guess is you created the environment variable using the System control panel or something equivalent, but your running copy of VS couldn't "see" it because it predated your change. – Eliot Gillum Nov 05 '18 at 19:38
  • 1
    Using command line, the updated value was available, but VS was still using the older value. – Kunal B. Nov 05 '18 at 20:06
0

With command prompt:

set GOOGLE_APPLICATION_CREDENTIALS=[PATH_JSON]

You don´t need setting credentials on code

Elialber Lopes
  • 633
  • 7
  • 18
-1

From google documention it seems it is env var and not web.config.

If you are using a service account credential, set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path to the JSON credential file you downloaded.

Daniel Rapaport
  • 375
  • 2
  • 18
  • yep, but I still have no idea where do I have the set the path – Steven Wang Jun 04 '16 at 06:40
  • Not sure I understand, have you try just adding ? https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_environmnt_addchange_variable.mspx?mfr=true – Daniel Rapaport Jun 04 '16 at 06:43
  • 1
    Thank you, I have just defined the GOOGLE_APPLICATION_CREDENTIALS and set the path, but still no luck – Steven Wang Jun 04 '16 at 06:56
-1

Google says:

After creating a service account, you have two choices for providing the credentials to your application. You can either set the GOOGLE_APPLICATION_CREDENTIALS environment variable explicitly, or you can pass the path to the service account key in code.

Mohsenne
  • 356
  • 5
  • 17