Deploying ASP.NET to Windows Azure cloud, applicat

2019-02-17 18:10发布

问题:

I am trying to deploy an ASP.NET application the Windows Azure cloud. I am using Google API for one of the calls in the application. When I do this, I get the following error:

System.UnauthorizedAccessException: Access to the path 'Google.Apis.Auth' is denied.`

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.`

To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.`

I tried researching this, but all the suggestions talk about changing the IIS server settings, which I don't believe I have access to since this is running in the cloud. Can anyone help?

EDIT: here is the code for the function that's giving the error:

 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`

回答1:

Try this.

A.If you have RDP Acces to the Azure cloud then change the IIS settings

  • 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 think you are using any local path. You should change this to local storage for temporary requirement and blob storage for long requirement.



回答2:

I had a similar problem and figured out that I would need to build my own IDataStore using Windows Azure Blob storage. My solution is in C#, but I posted my class file here: https://groups.google.com/d/msg/google-api-dotnet-client/s7i6mkMjX-M/p_4YlaOyLp4J Maybe that will help you some if you haven't already figured out another solution.



回答3:

Wrap the code that uses credential in the using statement. Closing the using statement disposes of the resources in the using statement, so when you try to access/use credential later in code, it has already been disposed.