为什么我得到 System.UnauthorizedAccessException 对路径

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"的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)