問題描述
我已經(jīng)實現(xiàn)了用于文件管理的谷歌驅(qū)動器功能,它在本地系統(tǒng)中工作正常,但是每當(dāng)我將它托管在 Godaddy 服務(wù)器上時,它都會拋出以下錯誤
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 來實現(xiàn)上述功能
I am using VS2010,IIS 7 for above functionality
推薦答案
擴展 Chandrika 已經(jīng)說過的內(nèi)容,ASP.NET 用戶需要對 Google API 客戶端 OAuth2 庫的永久存儲文件夾的讀寫權(quán)限.
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 .
其默認(rèn)值為Environment.SpecialFolder.ApplicationData
中名為Google.Apis.Auth"的文件夾(通常對應(yīng)于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
這篇關(guān)于為什么我得到 System.UnauthorizedAccessException 對路徑“Google.Apis.Auth"的訪問被拒絕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!