对“C:\ Windows \ system32 \ config \ systemprofile”路径的访问被拒绝

我正在使用Google Calendar Api和我的一个项目。 我不知道如何,但下面显示的错误是令人不安的。

这是错误

堆栈错误跟踪

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下面的解决方案但是没有用

我试过这个解决方案

以上解决方案对我没有用,如果有任何答案请帮忙。

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

从我刚提供的代码中你可以看到我正在使用File2DataStore。 它被我超越了。 标准FileDataStore我改变了我自己的需求。 标准FileDataStore将身份validation密钥存储在“C:\ WINDOWS \ system32 \ config \ systemprofile \ AppData \ Roaming \ 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并编写自己的替换(使用上面的链接作为起点)。

问题是默认情况下

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

将数据存储在需要特殊权限的路径中,因此将完整路径作为参数发送。

代替

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

例如,将完整路径发送到要保存在文件系统中的位置,将第二个参数设置为true

  new FileDataStore(fullpath, true); 

这应该工作。 祝好运

我不知道谷歌API …但该文件夹具有特定的安全性,只允许访问Administrators组成员。

也许用户(由IIS或Visual Studio使用)必须是本地计算机Administrator组(\ Administrator)的成员。

顺便说一下,在Visual Studio中,您必须以管理员身份启动。