2014-05-01 97 views
6

我在本地系统中实现谷歌驱动器功能进行文件管理其工作正常,但每当我主持这Godaddy的服务器上扔了以下错误为什么会System.UnauthorizedAccessException的访问路径“Google.Apis.Auth”被拒绝

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的上述功能

+0

如何共享导致此异常的代码行(也许它配置?) – rene

+0

以上UserCredential相关的代码,我使用该 –

+0

它在该行不成? – rene

回答

0

我想在这里你会找到一个解决方案:Deploying ASP.NET to Windows Azure cloud, application gives error when running on cloud

你只需要配置IIS与FileDataStore工作。

以下是从答案那里复制:

A.如果你有RDP查看在Azure云然后更改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. 

B.I认为你正在使用任何本地路径。您应该将其更改为用于临时需求的本地存储和长时间需求的blob存储。问题的

+1

感谢所有的你宝贵的响应。 我的问题已解决,现在它的工作正常也在GoDadday服务器修改后的谷歌驱动器的api的源代码 –

+0

你有什么改变? – peleyal

+0

在这一行folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),文件夹)中将“Environment.SpecialFolder.ApplicationData”更改为“System.Web.HttpContext.Current.Server.MapPath(”YourFolderName“)” ; –

2

根本原因:是因为验证身份验证请求后,产生这一问题的创建窗口的用户的文件夹 下的目录和令牌文件,我们没有正确的是为Godadday服务器的那个文件夹,以便它不工作

解决方案:修改google apis [filedatasource.cs]的源代码,在我们的目录中创建该文件,并添加它的引用,它将起作用

+0

?我尝试过 var googleaccesstoken = System.Web.HttpContext.Current.Server.MapPath(“/ App_Data/MyGoogleStorage”);但没有运气 –

8

扩展Chandrika已经说过的内容,ASP.NET用户需要读写权限Google API客户端OAuth2库的永久存储文件夹。

其默认值是Environment.SpecialFolder.ApplicationData(通常对应于C:\Users\your-user-name\AppData\Roaming)中名为“Google.Apis.Auth”的文件夹。

或者,另一个文件夹可以为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

+0

添加到Google凭据调用第5个参数'新的FileDataStore(文件夹)'解决了问题。谢谢! – Riga

+0

我将该文件夹添加为相对路径,代码在'AuthorizeAsync'方法中挂起。任何想法? –

+0

什么是GDriveCreatedByUser? –

相关问题