【问题标题】:Deploying ASP.NET to Windows Azure cloud, application gives error when running on cloud将 ASP.NET 部署到 Windows Azure 云,应用程序在云上运行时出错
【发布时间】:2013-11-17 17:37:20
【问题描述】:

我正在尝试在 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`

【问题讨论】:

  • 在尝试响应之前,您能详细说明一下 Google API 调用吗?您是否希望它与文件系统中的已知/未知位置交互(看起来如此)?
  • @DavideB 我真的不这么认为,有2个调用,第一个是通过Oauth进行身份验证,第二个是使用Calendar API从Google Calendar中提取某些数据。它确实会在该过程中读取一个 JSON 文件,但不确定这是否算作“与文件系统交互”。
  • 您提到的 JSON 文件是否在物理上驻留在文件系统中?例如,当您在开发结构中进行本地测试时,它位于何处?
  • @DavideB 在项目中,在 App_Data 文件夹中。
  • 我希望该异常掩盖了实际的原始来源 - Google.Apis.Auth 程序集很可能具有对不存在或需要更高信任级别的某些内容的引用或依赖使用权。使用一些额外的调试来部署这部分代码,这些调试会迭代内部异常,直到您到达源代码并将堆栈跟踪打印到屏幕上。

标签: asp.net vb.net iis azure google-api-dotnet-client


【解决方案1】:

试试这个。

A。如果您拥有 Azure 云的 RDP 访问权限,请更改 IIS 设置

  • 1.进入IIS
  • 2.在站点下选择默认站点
  • 3.添加权限
  • 4.选择 I_User 对象并授予读/写访问权限。
  • 5.稍后您可以自动执行此设置using a batch file and startup task。

B。我认为您正在使用任何本地路径。 你应该把它改成local storage for temporary requirement and blob storage for long requirement.

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,并发现我需要使用 Windows Azure Blob 存储构建自己的 IDataStore。我的解决方案是 C#,但我在这里发布了我的类文件:https://groups.google.com/d/msg/google-api-dotnet-client/s7i6mkMjX-M/p_4YlaOyLp4J 如果您还没有找到其他解决方案,也许这会对您有所帮助。

    【讨论】:

      【解决方案3】:

      将使用credential 的代码包装在 using 语句中。关闭 using 语句会释放 using 语句中的资源,因此当您稍后在代码中尝试访问/使用 credential 时,它已经被释放了。

      【讨论】:

      • 不是已经在using 声明中了吗?你能告诉我这是什么样子吗?
      猜你喜欢
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      相关资源
      最近更新 更多