为什么我得到System.UnauthorizedAccessException拒绝访问路径’Google.Apis.Auth’被拒绝

我已经为文件管理实现了谷歌驱动器function,它在本地系统中工作正常,但每当我在Godaddy服务器上托管它时,它会抛出以下错误

System.UnauthorizedAccessException拒绝访问路径“Google.Apis.Auth”。

以下代码我正在使用:

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来实现上述function

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

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

或者,可以提供另一个文件夹作为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#credentials和https://developers.google.com/accounts/docs/OAuth2

问题的根本原因:生成此问题是因为在validation身份validation后请求其创建目录和令牌文件位于窗口的用户文件夹下,并且我们没有权利使用Godadday服务器的该文件夹,因此它无法正常工作

解决方案:修改了谷歌apis [ filedatasource.cs ]的源代码,用于在我们的目录中创建该文件,并添加它的引用,它将工作

我想你会在这里找到一个解决方案:将ASP.NET部署到Windows Azure云,应用程序在云上运行时会出错 。

您只需配置IIS即可使用FileDataStore。

从那里的答案复制以下内容:

答:如果您有到Azure云的RDP访问权限,则更改IIS设置

 1.Go to the IIS 2.Under sites select the Default site 3.Add Permission 4.choose I_User object and give read/write access. 5.later you can automate this setting using a batch file and startup task. 

BI认为您正在使用任何本地路径。 您应该将此更改为本地存储以用于临时要求和blob存储以满足长期要求。