2017-07-14 232 views
2

我正在使用Google Calendar Api與我的項目之一。我不知道如何,但下面顯示的錯誤令人不安。訪問路徑'C: Windows system32 config systemprofile'被拒絕

Here is the Error

Stack Trace of Error

代碼中AppFlowMetadata

public class AppFlowMetadata : FlowMetadata 
{ 
    private static readonly IAuthorizationCodeFlow flow = 
     new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer 
     { 
      ClientSecrets = new ClientSecrets 
      { 
       ClientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", 
       ClientSecret = "xxxxx_xxxxxxxxxxxxxxxxx" 
      }, 
      Scopes = new[] { CalendarService.Scope.Calendar }, 
      DataStore = new FileDataStore("Calendar.Api.Auth.Store") 
     }); 

    public override string GetUserId(Controller controller) 
    { 
     var user = controller.Session["UserID"]; 

     if (user == null) 
     { 
      user = Guid.NewGuid(); 
      controller.Session["UserID"] = user; 
     } 
     return user.ToString(); 

    } 

    public override IAuthorizationCodeFlow Flow 
    { 
     get { return flow; } 
    } 
} 

我嘗試以下解決方案從GitHub,但不工作

I tried this Solution

上述方案並沒有爲我工作,如果有任何一個答案,請幫助。

+0

提升你的過程。如果您從Visual Studio運行它,請以管理員身份啓動VS。或者以管理員身份運行您的程序。 –

+0

你有拋出異常的'AppFlowMetadata'類的源代碼嗎? – mjwills

+0

是的,我會嘗試重新啓動。 @VladimirArustamian,我會在'AppFlowMetadata'中添加代碼@mjwills – Divya

回答

-2

我不知道谷歌API ...但該文件夾有一個特定的安全,只允許訪問Administrators組成員。

也許用戶(由IIS或Visual Studio使用)必須是本地機器Administrator組(\ Administrator)的成員。

順便說一下,在Visual Studio中,您必須以管理員身份啓動。

3

https://domantasjovaisas.wordpress.com/2014/09/27/demystifying-google-api-and-oauth2/

從代碼,我只是提供你可以看到,我使用File2DataStore。 它被我覆蓋。標準FileDataStore我更改爲我自己的 需求。標準FileDataStore店權威性在 鍵「C:\ WINDOWS \ system32 \設置\ systemprofile \應用程序數據\漫遊\ Drive.Api.Auth.Store」

我不這樣你會允許用戶IIS_IUSRS訪問該 認爲在生產環境中的位置思考兩次,不要這樣做。 將FileDataSource重寫爲您自己的需要。下面是兩個例子,你 怎麼能做到這一點:

https://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis.DotNet4/Apis/Util/Store/FileDataStore.cs http://www.daimto.com/google-oauth2-csharp/#FileDataStore

總之,你需要停止使用FileDataStore,寫自己的更換(使用上面的鏈接,你的出發點)。

0

的問題是,在默認情況下

new FileDataStore("Calendar.Api.Auth.Store") 

存儲數據的路徑,需要特殊的權限,以便改爲發送完整的路徑作爲參數。

而不是

new FileDataStore("Calendar.Api.Auth.Store") 

發送完整路徑要在文件系統和第二個參數設置爲true,以節省例如

new FileDataStore(fullpath, true); 

這應該工作。 祝你好運