从azure部署的应用程序访问文件

时间:2018-03-10 20:18:25

标签: c# .net azure asp.net-core-mvc azure-web-sites

我制作了mvc .net核心应用程序,并且在我的应用程序中,我使用google服务进行google sheet api验证。在本地,一切都运行良好,但当我将应用程序部署到azure时,我遇到了一些错误。

  

"指定的CGI应用程序遇到错误和服务器   终止了这个过程。"

问题在于google sheet api的身份验证,因为我需要将json文件存储在应用程序的当前目录中,但是那里的东西不起作用。我尝试从我的vs 2017进行远程调试,但我无法解决问题。如果我删除带有google api身份验证的部分,一切正常。有什么建议吗?感谢。

    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;
    }

0 个答案:

没有答案