2017-07-14 62 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); 

这应该工作。 祝你好运

相关问题