Cha*_*ati 6 c# asp.net iis-7 google-drive-api
我已经为文件管理实现了谷歌驱动器功能,它在本地系统中运行良好,但每当我在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;
Run Code Online (Sandbox Code Playgroud)
我正在使用VS2010,IIS 7来实现上述功能
扩展Chandrika已经说过的内容,ASP.NET用户需要对Google API客户端OAuth2库的永久存储文件夹具有读写权限.
它的默认值是一个名为"Google.Apis.Auth"的文件夹Environment.SpecialFolder.ApplicationData(通常对应于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;
Run Code Online (Sandbox Code Playgroud)
请参阅:https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentials和https://developers.google.com/accounts/docs/OAuth2
我想您会在这里找到解决方案:将 ASP.NET 部署到 Windows Azure 云,应用程序在云上运行时出现错误。
您只需配置 IIS 即可使用 FileDataStore。
以下内容是从那里的答案复制的:
A.如果您有 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.
Run Code Online (Sandbox Code Playgroud)
BI 认为您正在使用任何本地路径。对于临时需求,您应该将其更改为本地存储,对于长期需求,应将其更改为 Blob 存储。
| 归档时间: |
|
| 查看次数: |
13954 次 |
| 最近记录: |