簡體   English   中英

為什么我得到System.UnauthorizedAccessException拒絕訪問路徑'Google.Apis.Auth'被拒絕

[英]Why do I get System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied

我已經為文件管理實現了谷歌驅動器功能,它在本地系統中運行良好,但每當我在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來實現上述功能

擴展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#credentialshttps://developers.google.com/accounts/docs/OAuth2

問題的根本原因:生成此問題是因為在驗證身份驗證后請求其創建目錄和令牌文件位於窗口的用戶文件夾下,並且我們沒有權利使用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存儲以滿足長期要求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM