title: The remote server returned an error: (400) Bad Request. Geolocation
body: <p>i can find more errors with the same heading. but did not give the solution of mine. i am try to create small application to get the user location , and reverse it. all are good working fine. When i tested with my pc and publish it was working fine and no errors at all. Now i try to put it in another pc(IIS) trying to access from my pc application running perfect but when it reach to read the location its throwing the above error. i did some google most of them are saying authentication problem,or time out issue. but it was in my pc work perfect even in(IIS), i try to access from other laptop and all work good. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Server Error in '/' Application.
  The remote server returned an error: (400) Bad Request.
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
  
  Source Error: 
  
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  Stack Trace: 
  
  
  [WebException: The remote server returned an error: (400) Bad Request.]
     System.Net.HttpWebRequest.GetResponse() +1695
     System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) +105
     System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +86
     System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) +71
     System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0
     System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) +112
     System.Xml.XmlTextReaderImpl.OpenUrl() +396
     System.Xml.XmlTextReaderImpl.Read() +296
     System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +158
     System.Xml.XmlDocument.Load(XmlReader reader) +134
     System.Xml.XmlDocument.Load(String filename) +146
     WiseDistribution.Settings.usrProfile.getlocationname() in D:\Projects\UserLocation\Settings\usrProfile.aspx.cs:190
     WiseDistribution.Settings.usrProfile.imgUpdate_Click(Object sender, ImageClickEventArgs e) in D:\Projects\UserLocation\Settings\usrProfile.aspx.cs:152
     System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +138
     System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +186
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1665</code></pre>
  </div>
  </div>
  </p>
  
  <p>this is error i am getting. </p>
  
  <p>my config file is. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;appSettings&gt;   
     Connection string
    &lt;/appSettings&gt;
    &lt;connectionStrings&gt;
   &lt;add name="Excel03ConString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'" /&gt;
      &lt;add name="Excel07ConString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR={1}'" /&gt;
    &lt;/connectionStrings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" /&gt;
      &lt;pages&gt;
        &lt;namespaces&gt;
          &lt;add namespace="System.Web.Optimization" /&gt;
        &lt;/namespaces&gt;
        &lt;controls&gt;
          &lt;add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" /&gt;
        &lt;/controls&gt;
      &lt;/pages&gt;
      &lt;authentication mode="Forms"&gt;
        &lt;forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" /&gt;
      &lt;/authentication&gt;
      &lt;profile defaultProvider="DefaultProfileProvider"&gt;
        &lt;providers&gt;
          &lt;add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /&gt;
        &lt;/providers&gt;
      &lt;/profile&gt;
      &lt;membership defaultProvider="DefaultMembershipProvider"&gt;
        &lt;providers&gt;
          &lt;add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /&gt;
        &lt;/providers&gt;
      &lt;/membership&gt;
      &lt;roleManager defaultProvider="DefaultRoleProvider"&gt;
        &lt;providers&gt;
          &lt;add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /&gt;
        &lt;/providers&gt;
      &lt;/roleManager&gt;
      &lt;sessionState mode="InProc" customProvider="DefaultSessionProvider"&gt;
        &lt;providers&gt;
          &lt;add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /&gt;
        &lt;/providers&gt;
      &lt;/sessionState&gt;
    &lt;/system.web&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v11.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Really no idea where is the problem. All location tracing button click return the same error. And same time if i try to debug(run visual studio) from my pc i am not getting any error, even i use the remote server database and webconfig file. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://maps.googleapis.com/maps/api/js?key=abcdeff&amp;callback=myMap"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              var longitude = $('#longitude');
              var latitude = $('#latitude');
              var hiddenControl = '&lt;%= inpHide.ClientID %&gt;';
              if (navigator.geolocation) {
                  navigator.geolocation.getCurrentPosition(function (p) {
                      console.log(longitude);
                      longitude.text(p.coords.longitude);
                      latitude.text(p.coords.latitude);
                      document.getElementById(hiddenControl).value=p.coords.latitude + "," + p.coords.longitude;
                      var LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
                   //   alert(p.coords.latitude);
                      var mapOptions = {
                          center: LatLng,
                          zoom: 20,
                          mapTypeId: google.maps.MapTypeId.ROADMAP
                      };
                      var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
                      var marker = new google.maps.Marker({
                          position: LatLng,
                          map: map,
                          title: "&lt;div style = 'height:60px;width:200px'&gt;&lt;b&gt;Your location:&lt;/b&gt;&lt;br /&gt;Latitude: " + p.coords.latitude + "&lt;br /&gt;Longitude: " + p.coords.longitude,
  
                      });
                      google.maps.event.addListener(marker, "click", function (e) {
                          var infoWindow = new google.maps.InfoWindow();
                          infoWindow.setContent(marker.title);
                          infoWindow.open(map, marker);
                      });
                  });
              } else {
                  alert('Location feature is not supported in this browser.');
              }
          });
      &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>this is html side javascript code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> public void getlocationname()
          {
              //  string coordinate = latitude.InnerText + "," + longitude.InnerText; // "32.797821,-96.781720"; 
              string coordinate = inpHide.Value;
              XmlDocument xDoc = new XmlDocument();
              //  xDoc.Load("https://maps.googleapis.com/maps/api/geocode/xml?latlng=" + coordinate);
              xDoc.Load("https://maps.google.com/maps/api/geocode/xml?key=abcdff&amp;callback&amp;latlng=" + coordinate + "&amp;sensor=false");
              XmlNodeList xNodelst = xDoc.GetElementsByTagName("result");
              XmlNode xNode = xNodelst.Item(0);
              string FullAddress = xNode.SelectSingleNode("formatted_address").InnerText;
              string Number = xNode.SelectSingleNode("address_component[1]/long_name").InnerText;
              string Street = xNode.SelectSingleNode("address_component[2]/long_name").InnerText;
              string Village = xNode.SelectSingleNode("address_component[3]/long_name").InnerText;
              string Area = xNode.SelectSingleNode("address_component[4]/long_name").InnerText;
              string County = xNode.SelectSingleNode("address_component[5]/long_name").InnerText;
  
              locationName = FullAddress;
          }</code></pre>
  </div>
  </div>
  </p>
  
  <p>code behind to get location name(for saving the data)</p>