0

I made mvc .net core app, and in my app I net to authenticate with a google services for google sheet api. Locally, everything works well, but when I deploy the app to azure I got some error.

"The specified CGI application encountered an error and the server terminated the process."

The problem is with the authentication to the google sheet api because I need to store the json file in the current directory of the app, but something there it is not working. I tried to make a remote debugging from my vs 2017 but I cannot solve the problem. If I delete the part with the authentication to the google api everything works well. Any suggestion? Thanks.

    public HomeController()
    {

        var directory = Directory.GetCurrentDirectory();
        var pathForJson = Path.Combine(directory, "client_secret.json");
        var credential = GetNormalCredential(scopes, pathForJson, "sheets.googleapis.com-dotnet-quickstart.json");
    //    _sheetsService = (SheetsService)GoogleSheetFactoryService.GetService("Sheet", applicationName, credential);

        var builder = new ConfigurationBuilder()
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("appsettings.json");

        var configuration = builder.Build();
        AzureUrl = configuration["AppConfiguration:AzureUrl"];
        AzureUrlGet = configuration["AppConfiguration:AzureUrlGet"];

    }

     public  UserCredential GetNormalCredential(string[] scopes, string clientJsonPathFile, string clientCombinePath)
    {
        UserCredential credential;
        using (var stream =
            new FileStream(clientJsonPathFile, FileMode.Open, FileAccess.Read))
        {
            string credPath = Directory.GetCurrentDirectory();
            string secondPath = @".credentials\sheets.googleapis.com-dotnet-quickstart.json";

            credPath = Path.Combine(credPath, secondPath); 
            Debug.WriteLine("Credential file saved to: " + credPath);
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;

        }

        return credential;
    }
user9405863
  • 1,506
  • 1
  • 11
  • 16
  • I had a similar problem once and I was able to resolve it by removing the forwardWindowsAuthToken = 'false/true' in httpPlatform section in web.config. Had to redeploy the app – Johny Mar 11 '18 at 00:26
  • @Johny, this is a .net core 2.0 app. I don't have an web.config section. – Vasilut Lucian Mar 11 '18 at 15:23
  • I don't have the web.config file. – Vasilut Lucian Mar 12 '18 at 09:11
  • Have you tried to delete the old files and republish the app? It deserves a try according to Tom Markin's answer in [this question](https://stackoverflow.com/questions/33645242/the-specified-cgi-application-encountered-an-error-and-the-server-terminated-the) – Jerry Liu Mar 13 '18 at 01:23

0 Answers0