0

I inherited a web app written in c#/MVC (.NET 4.0)

The only page that is giving trouble is the one that accesses Google Maps. It is consistently giving me the dreaded forbidden 403 error. The identical issue is occurring on I should mention that this had been working for many months without issue, and just all of a sudden started occurring. It is conceivable that a Windows Update may have initiated this problem. Are there any IIS settings or User Permissions I could modify that would prevent this issue from occuring. I tried temporarily given Full Access to the Everyone user, but this made no difference. Here is all the details I can provide:

[WebException: The remote server returned an error: (403) Forbidden.]
   System.Net.HttpWebRequest.GetResponse() +1646
   System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) +129
   System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +86
   System.Xml.XmlTextReaderImpl.FinishInitUriString() +90
   System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext) +99
   System.Xml.Linq.XDocument.Load(String uri, LoadOptions options) +84
   GoogleMaps.LocationServices.GoogleLocationService.GetLatLongFromAddress(String address) +165
   URS.Web.Controllers.TherapistController.GetPatientLatLong(String address) +70
   URS.Web.Controllers.TherapistController.ShowReferral(Int32 RefId, Int32 Disciplineid, Int32 ReferalDetailsId, String pagenumber) +603
   lambda_method(Closure , ControllerBase , Object[] ) +307
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +71
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +72
   System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +385
   System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +385
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +607
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134

In my Controller file, the only method that uses Google Maps is the following:

private Dictionary<string, double> GetPatientLatLong(string address)
    {
        Dictionary<string, double> latlong = new Dictionary<string, double>();

        var Patientadd = address;

        var locationService = new GoogleLocationService();
        var point = locationService.GetLatLongFromAddress(Patientadd);
        if (point != null)
        {
            var latitude = point.Latitude;
            var longitude = point.Longitude;
            latlong.Add("latitude", latitude);
            latlong.Add("longitude", longitude);
        }
        else
        {
            latlong.Add("latitude", 0);
            latlong.Add("longitude", 0);
        }
        return latlong;

    }

In the .cshtml file, this is written at the top

<script src="https://maps.googleapis.com/maps/api/js?key={thekey}"></script>

followed by:

<script>

google.maps.event.addDomListener(window, 'load', initialize);

  function initialize() {

        var markerArray = [];
        var infoWindow = new google.maps.InfoWindow();
        var miles = @Model.TherapRadius;
        var myLatlng1 = new google.maps.LatLng(@Model.TherapLat, @Model.TherapLong);
        var myLatlng2 = new google.maps.LatLng(@Model.patientLat, @Model.patientLong);
        var mapOptions = {
            center: new google.maps.LatLng(29.760193,-95.369390),
            zoom:10,
        }
        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
        var geocoder = new google.maps.Geocoder();
        var marker1;

        for (var i = 0; i < myModel.coveringAreas.length; i++) {

            var markerloop = new google.maps.Marker({
                position:  new google.maps.LatLng( myModel.coveringAreas[i].Latitude, myModel.coveringAreas[i].Longitude),
                map: map,
                title: 'Therapist Location: ' + myModel.coveringAreas[i].TherapistName
            });
            var markerModel = myModel.coveringAreas[i];

            markerArray.push( { marker :  markerloop, markerModl : markerModel });
        }

        var marker2 = new google.maps.Marker({
            position: myLatlng2,
            map: map,
            title: 'Patient Location',
            color:"Blue",
            icon:"http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png"
        });

        marker2.setMap(map);

        for (i = 0; i < markerArray.length; i++) {
            addMarkerDetails(i);
        }
}
        function addMarkerDetails(i)
        {
            var listenerMarker = markerArray[i].marker;
            var therapistDetails = markerArray[i].markerModl;
            google.maps.event.addListener(listenerMarker, 'click', function(e) {
                var clickText = "<div id='infoDiv'>" +
                               "<h3>Therapist Name:</h3>" + therapistDetails.TherapistName + "" +
                               //"<h3>Address:</h3>" + therapistDetails.Location +
                               "<div>" ;
                infoWindow.setContent(clickText);
                infoWindow.open(listenerMarker.get('map'), listenerMarker);
            });

            google.maps.event.addListener(marker2, 'click', function(e) {

                var clickText = "<div id='infoDiv'>" +
                                "<h3>Patient Name:</h3>" + '@Model.LastName' +", "+ '@Model.FirstName' + "" +
                               "<h3>Address:</h3>" +  '@Model.PatientFullAddress'+
                               "<div>" ;

                    infoWindow.setContent(clickText);
                    infoWindow.open(map, this);

                });
            }

            var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
                this.setZoom(10);
                google.maps.event.removeListener(boundsListener);
            });

        }

</script>

Here is an entry from the Event Viewer:

Log Name:      Application
Source:        ASP.NET 4.0.30319.0
Date:          08/28/18 9:58:55 AM
Event ID:      1309
Task Category: Web Event
Level:         Warning
Keywords:      Classic
User:          N/A
Computer:      MyWeb
Description:
Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 8/28/2018 9:58:55 AM 
Event time (UTC): 8/28/2018 2:58:55 PM 
Event ID: 755907cfe9ef41ae875f99ef89aa9abb 
Event sequence: 658 
Event occurrence: 6 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/2/ROOT-1-131799399080579812 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: C:\inetpub\wwwroot\MYWEB\ 
    Machine name: MYWEB 

Process information: 
    Process ID: 2012 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\MYWEB 

Exception information: 
    Exception type: WebException 
    Exception message: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.GetResponse()
   at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
   at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
   at System.Xml.XmlTextReaderImpl.FinishInitUriString()
   at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
   at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
   at GoogleMaps.LocationServices.GoogleLocationService.GetLatLongFromAddress(String address)
   at MYWEB.Web.Controllers.TherapistController.GetPatientLatLong(String address)
   at MYWEB.Web.Controllers.TherapistController.GetPatientCoordinates(Int32 id)
   at MYWEB.Web.Controllers.TherapistController.GetAllTherapist(DataSourceRequest request, Int32 disciplineId, Int32 refDetailId)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



Request information: 
    Request URL: http://ursuatweb.southcentralus.cloudapp.azure.com/Therapist/GetAllTherapist/?disciplineId=1&refDetailId=1805 
    Request path: /Therapist/GetAllTherapist/ 
    User host address: 75.107.154.176 
    User: Richardmartin 
    Is authenticated: True 
    Authentication Type: cookie 
    Thread account name: IIS APPPOOL\MYWEB 

Thread information: 
    Thread ID: 22 
    Thread account name: IIS APPPOOL\MYWEB 
    Is impersonating: False 
    Stack trace:    at System.Net.HttpWebRequest.GetResponse()
   at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
   at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
   at System.Xml.XmlTextReaderImpl.FinishInitUriString()
   at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
   at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
   at GoogleMaps.LocationServices.GoogleLocationService.GetLatLongFromAddress(String address)
   at MYWEB.Web.Controllers.TherapistController.GetPatientLatLong(String address)
   at MYWEB.Web.Controllers.TherapistController.GetPatientCoordinates(Int32 id)
   at MYWEB.Web.Controllers.TherapistController.GetAllTherapist(DataSourceRequest request, Int32 disciplineId, Int32 refDetailId)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Richard Martin
  • 131
  • 1
  • 9
  • Are you sure this isn't related to the [Maps billing changes](https://stackoverflow.com/questions/50482154/is-it-compulsory-to-enable-billing-account-by-june-11-2018-through-credit-card)? As a test, can you make any requests using your access key? – stuartd Aug 28 '18 at 15:39
  • It was working after these changes went into effect. It only stopped working a few days ago. I did, however, do this following test with the link from the Google Maps documentation, and it worked just fine: https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key={mykey} – Richard Martin Aug 28 '18 at 16:27
  • The reason I asked is because as the answer there says - _"a billing account without any credit card information will be created for each project without billing account. This means that the API calls will still succeed, as long as they fit within the free tier of $200 per month. If your application goes over the 200$ free tier, the billing account will be closed, and API calls will start failing"_ - have you checked your project to see the status of the billing account? – stuartd Aug 28 '18 at 16:34
  • Yes, I read that also, and I am having it checked into. Thank you for the suggestion. – Richard Martin Aug 28 '18 at 16:37
  • You does not seem to be using Google API directly, but an open source project, https://github.com/sethwebster/GoogleMaps.LocationServices That can be the problem, as the library hasn't been updated for a year, while Google Maps is a moving target which can break any old library. Try to find a more up-to-date library to replace the one you use, or switch to Google API natively. – Lex Li Aug 28 '18 at 20:45

0 Answers0