为什么我得到 System.UnauthorizedAccessException 对路径“Google.Apis.Au

Why do I get System.UnauthorizedAccessException Access to the path #39;Google.Apis.Auth#39; is denied(为什么我得到 System.UnauthorizedAccessException 对路径“Google.Apis.Auth的访问被拒绝)
本文介绍了为什么我得到 System.UnauthorizedAccessException 对路径“Google.Apis.Auth"的访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I have implemented google drive functionality for file management its working fine in local system but whenever i hosted it on Godaddy server it throw following error

System.UnauthorizedAccessException拒绝访问路径Google.Apis.Auth".

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

I am using VS2010,IIS 7 for above functionality

推荐答案

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

Expanding what Chandrika has already said, the ASP.NET user needs read and write permissions to the Google API Client OAuth2 Library's permanent storage folder .

其默认值为Environment.SpecialFolder.ApplicationData中名为Google.Apis.Auth"的文件夹(通常对应于C:Usersyour-user-nameAppData漫游).

Its default value is a folder named "Google.Apis.Auth" in Environment.SpecialFolder.ApplicationData (which usually corresponds to C:Usersyour-user-nameAppDataRoaming).

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

Alternatively, another folder can be provided as the last parameter of the GoogleWebAuthorizationBroker.AuthorizeAsync() method:

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

这篇关于为什么我得到 System.UnauthorizedAccessException 对路径“Google.Apis.Auth"的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)
RabbitMQ asynchronous support(RabbitMQ 异步支持)