0
votes

I was created MVC web app to post event on google calendar. after meany attempts it worked fine in localhost. but today when i host it in a online iis webserver it giving following error message, (all the google settings in developer account done correctly )

here is my code:

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                                                          new ClientSecrets
                                                          {
                                                              ClientId = siteinfoCalendar.ClientId,
                                                              ClientSecret = siteinfoCalendar.ClientSecret,

                                                          },
                                                          new[] { CalendarService.Scope.Calendar },
                                                          townName,
                                                          CancellationToken.None,
                                                          new DBDataStotre()).Result;

                    // Create Google Calendar API service.
                    var service = new CalendarService(new BaseClientService.Initializer()
                    {
                        HttpClientInitializer = credential,
                        ApplicationName = siteInfo.TownName,
                    });
                    string description = calendarInfo.FirstOrDefault().Issue.Replace("&amp;", "").Replace("&lt;", "").Replace("&gt;", "").Replace("&quot;", "").Replace("&apos;", "").Replace("<br />", "").Replace("&nbsp;", "");
                    Event newPtoEvent = new Event();
                    newPtoEvent.Summary = calendarInfo.FirstOrDefault().UserName + " on " + leaveDescription.Trim() + " leave.";
                    newPtoEvent.Description = calendarInfo.FirstOrDefault().Issue;
                    newPtoEvent.Start = new EventDateTime();
                    newPtoEvent.Start.DateTime = calendarInfo.FirstOrDefault().StartDateLocalTime;
                    newPtoEvent.End = new EventDateTime();
                    newPtoEvent.End.DateTime = calendarInfo.FirstOrDefault().EndDateLocalTime;

                    var createCalendarEvent = service.Events.Insert(newPtoEvent, siteinfoCalendar.CalendarID);

                    Task.Run(() => { createCalendarEvent.Execute(); });

it was worked on localhost with no issue, but now when it is hosted on iis hosting server, it giving bellow stack trace error message:

One or more errors occurred. mscorlib at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at LibTsService.ServiceRequests.GoogleCalendar.PTOCalendarUpdate.UpdateClendar(Int32 complaintId, IDbConnection& con) at LibTsService.ServiceRequests.SrStatusUpdateService.DeclineApprovePto(Boolean isStaffMember) at LibTsService.ServiceRequests.SrStatusUpdateService.Any(SrStatusUpdate request) Access is denied System at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() Exception.ToString(): System.AggregateException: One or more errors occurred. ---> System.ComponentModel.Win32Exception: Access is denied at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() --- End of inner exception stack trace ---

So what is the reason for this to not working in online host ?

1
do you get successful insert locally with this? var insertevent = calservice.Events.Insert(calendarEvent, URL); var requestedInsert = insertevent.Execute(); I noticed you have a slight difference with the task being used vs what I have used in the past.HighlanderGrog

1 Answers

0
votes

I ran through similar issue. The library supports another way of authenticating for use with Web Apps. I Modifies my code a little bit. Here is the code snippet.

 ClientSecrets cs = new ClientSecrets
        {
            ClientId = "Put_Your_Client_Id_Here",
            ClientSecret = "Put_Your_Client_Secret_Here"
        };
        string ApplicationName = "Google Calendar API .NET Quickstart";
         //Path where Json File is stored
        FileDataStore store = new FileDataStore(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/Template/credentials/calendar-dotnet-quickstart.json/calendar-dotnet-quickstart.json"), true);
        UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(cs, Scopes, "user", CancellationToken.None, store).Result;
        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = ApplicationName,
        });