c# - 为什么我得到 System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied

标签 c# asp.net iis-7 google-drive-api

我已经实现了用于文件管理的谷歌驱动器功能,它在本地系统中运行良好,但每当我将它托管在 Godaddy 服务器上时,它就会抛出以下错误

System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied.

我正在使用以下代码:

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
   new ClientSecrets
   {
       ClientId = System.Configuration.ConfigurationManager.AppSettings["GDriveClientId"],//Get ClientID from web.config.
       ClientSecret = System.Configuration.ConfigurationManager.AppSettings["GDriveClientSecret"]//Get ClientSecret from web.config.
   },
   new[] { DriveService.Scope.Drive },
   System.Configuration.ConfigurationManager.AppSettings["GDriveCreatedByUser"],//Get UserName from web.config.
   CancellationToken.None).Result;

return credential;

我正在使用 VS2010,IIS 7 来实现上述功能

最佳答案

扩展 Chandrika 已经说过的内容,ASP.NET 用户需要对 Google API 客户端 OAuth2 库的永久存储文件夹具有读写权限。

它的默认值是 Environment.SpecialFolder.ApplicationData 中名为“Google.Apis.Auth”的文件夹(通常对应于 C:\Users\your-user-name\AppData\漫游)。

或者,可以提供另一个文件夹作为 GoogleWebAuthorizationBroker.AuthorizeAsync() 的最后一个参数方法:

var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
   new ClientSecrets
   {
       ClientId = "PutYourClientIdHere",
       ClientSecret = "PutYourClientSecretHere"
   },
   new[] { DriveService.Scope.Drive },
   "user",
   CancellationToken.None,
   new FileDataStore(folder)).Result;

return credential;

参见:https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentialshttps://developers.google.com/accounts/docs/OAuth2

关于c# - 为什么我得到 System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23405767/

相关文章:

c# - DocX表格,如何设置表头背景颜色?

c# - asp.net、c#、用户提供的连接字符串和查询

c# - 偶尔的异常 : "A network-related or instance-specific error occurred while establishing a connection to SQL Server"

asp.net - 使用具有 jQuery 引用的母版页时,内容页面中的 jQuery 未定义

asp.net - 奇怪的 ASP.NET 错误!

c# - 如何为元素设置值?

c# - Canvas ActualWidth 和 ActualHeight 以 MVVM 方式传入 ViewModel

asp.net - 在 IIS7 上运行时如何将 maxAllowedContentLength 设置为 500MB?

c# - Cortana 回复而不是应用程序启动

asp.net-mvc - 将 MVC 2 应用程序添加到 IIS 7 中的 Nancy 站点