Why do I get System.UnauthorizedAccessException Access to the path #39;Google.Apis.Auth#39; is denied(为什么我得到 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"的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我得到 System.UnauthorizedAccessException 对路径


基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01