Search code examples
iisxmldocument

XmlDocument Load unauthorized


.cshtml file with the following code:

XmlDocument xd = new XmlDocument();
xd.Load("http://remote_server/login/MyService.asmx/GetSearchData?Search="test"

returns "System.Net.WebException: The remote server returned an error: (401) Unauthorized" from some IIS servers but works fine on others:

  • IIS in Windows 10: Works
  • IIS server on SmarterASP.net: Works
  • Started from Visual Studio Community 2013 (version 12) .NET 4.6: Works
  • Started from Visual Studio Community 2015 (version 14) .NET 4.6: Returns error above
  • IIS 7 on windows server 2008 R2 .NET 4.0: Returns error above

Is this a IIS configuration issue?


Solution

  • Strange error, but since the webservice was on the same server as this page (windows server, last line above), we changed the address for the xd.load to:

    xd.Load("http://localhost/login/MyService.asmx/GetSearchData?Search="test"
    

    Worked fine then.