Art*_*t F 5 vb.net asp.net iis azure google-api-dotnet-client
我正在尝试在Windows Azure云中部署ASP.NET应用程序.我正在为应用程序中的一个调用使用Google API.当我这样做时,我收到以下错误:
System.UnauthorizedAccessException:拒绝访问路径'Google.Apis.Auth'
ASP.NET无权访问所请求的资源.考虑将资源的访问权限授予ASP.NET请求标识.ASP.NET具有基本进程标识(IIS 5上通常为{MACHINE}\ASPNET,IIS 6和IIS 7上为网络服务,IIS 7.5上已配置的应用程序池标识),如果应用程序未模拟,则使用该标识.如果应用程序模拟通过,则标识将是匿名用户(通常为IUSR_MACHINENAME)或经过身份验证的请求用户.
要授予对文件的ASP.NET访问权限,请在"文件资源管理器"中右键单击该文件,选择"属性",然后选择"安全"选项卡.单击"添加"以添加适当的用户或组.突出显示ASP.NET帐户,并选中所需访问的框
我试过研究这个,但所有的建议都谈到了改变IIS服务器的设置,我不相信我有权访问,因为它在云中运行.有人可以帮忙吗?
编辑:这是给出错误的函数的代码:
Async Function SpecialTest() As Task(Of String)
Dim credential As UserCredential
Dim clientSecretsPath As String = Server.MapPath("~/App_Data/client_secret.json")
Dim scopes As IList(Of String) = New List(Of String)()
scopes.Add(CalendarService.Scope.Calendar)
Dim stream As FileStream = New FileStream(clientSecretsPath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Using stream
credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, scopes, "user3", CancellationToken.None)
End Using
Dim baseInitializer = New BaseClientService.Initializer()
With baseInitializer
.HttpClientInitializer = credential
.ApplicationName = "P1"
End With
Dim service = New CalendarService(baseInitializer)
Dim Calendars = (Await service.CalendarList.List().ExecuteAsync()).Items()
Dim toReturn As String = "{""items"": ["
For Each firstCalendar As CalendarListEntry In Calendars
If firstCalendar IsNot Nothing Then
' Get all events from the first calendar.
Dim calEvents = Await service.Events.List(firstCalendar.Id).ExecuteAsync()
' DO SOMETHING
Dim items = calEvents.Items
'Return JsonConvert.SerializeObject(calEvents)
For Each ite As Google.Apis.Calendar.v3.Data.Event In items
If Not (ite.Location Is Nothing) And Not (ite.Start Is Nothing) Then
Dim tst = ite.Start.DateTime
toReturn = toReturn + " [""" + Date.Parse(ite.Start.DateTime).ToShortDateString + """" + "," + """" + ite.Location + """" + "," + """" + ite.Start.DateTime + """" + "," + """" + ite.Start.DateTime + """" + "," + """""],"
End If
Next
End If
Next
toReturn = toReturn.Substring(0, toReturn.Length - 1)
Return toReturn + "]}"
End Function`
Run Code Online (Sandbox Code Playgroud)
vip*_*naz -1
将使用的代码包装credential在 using 语句中。关闭 using 语句会释放 using 语句中的资源,因此当您稍后在代码中尝试访问/使用时credential,它已经被释放了。
| 归档时间: |
|
| 查看次数: |
3025 次 |
| 最近记录: |