Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. The remote server returned an error: (401) Unauthorized.

The remote server returned an error: (401) Unauthorized.

Scheduled Pinned Locked Moved ASP.NET
csharpdesignsysadminxmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Evan Schultz
    wrote on last edited by
    #1

    I'm working on a web application for a local intranet, and I've run into a bit of a snag. Initially, I didnt think and had left anon access enabled on the web I was developing on, then as I hit a point where I needed to keep track of the current logged in user, I disabled anon access so I could use the ttpContext.Current.User.Identity.Name.ToString(); However, I am now getting the error [WebException: The remote server returned an error: (401) Unauthorized.] System.Net.HttpWebRequest.CheckFinalStatus() System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) System.Net.HttpWebRequest.GetResponse() System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +94 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +55 System.Xml.XmlTextReader.CreateScanner() +384 System.Xml.XmlTextReader.Init() +23 System.Xml.XmlTextReader.Read() +530 WorkOrders.WOGrid.LoadConfig(String key) in \\enterprisedev1\wwwroot$\workorders\wogrid.ascx.cs:387 WorkOrders.WOGrid.SetupColumns() in \\enterprisedev1\wwwroot$\workorders\wogrid.ascx.cs:422 WorkOrders.WOGrid.OnInit(EventArgs e) in \\enterprisedev1\wwwroot$\workorders\wogrid.ascx.cs:471 System.Web.UI.Control.InitRecursive(Control namingContainer) +241 System.Web.UI.Control.InitRecursive(Control namingContainer) +179 System.Web.UI.Control.InitRecursive(Control namingContainer) +179 System.Web.UI.Page.ProcessRequestMain() +197 any idea how to resolve this? Thanks - Evan

    M 1 Reply Last reply
    0
    • E Evan Schultz

      I'm working on a web application for a local intranet, and I've run into a bit of a snag. Initially, I didnt think and had left anon access enabled on the web I was developing on, then as I hit a point where I needed to keep track of the current logged in user, I disabled anon access so I could use the ttpContext.Current.User.Identity.Name.ToString(); However, I am now getting the error [WebException: The remote server returned an error: (401) Unauthorized.] System.Net.HttpWebRequest.CheckFinalStatus() System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) System.Net.HttpWebRequest.GetResponse() System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +94 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +55 System.Xml.XmlTextReader.CreateScanner() +384 System.Xml.XmlTextReader.Init() +23 System.Xml.XmlTextReader.Read() +530 WorkOrders.WOGrid.LoadConfig(String key) in \\enterprisedev1\wwwroot$\workorders\wogrid.ascx.cs:387 WorkOrders.WOGrid.SetupColumns() in \\enterprisedev1\wwwroot$\workorders\wogrid.ascx.cs:422 WorkOrders.WOGrid.OnInit(EventArgs e) in \\enterprisedev1\wwwroot$\workorders\wogrid.ascx.cs:471 System.Web.UI.Control.InitRecursive(Control namingContainer) +241 System.Web.UI.Control.InitRecursive(Control namingContainer) +179 System.Web.UI.Control.InitRecursive(Control namingContainer) +179 System.Web.UI.Page.ProcessRequestMain() +197 any idea how to resolve this? Thanks - Evan

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, I think that you are trying to access an xml file at line 387 in the wogrid.ascx.cs file, however, the error occurs as you disable anonymous access. In this case, you may have to explicitly specify a credential that has permission to access the xml file. The sample code looks like:

      ...
      string url = "...";
      XmlTextReader reader = new XmlTextReader (url);

      XmlUrlResolver resolver = new XmlUrlResolver();
      resolver.Credentials = CredentialCache.DefaultCredentials;

      //You can also specify another valid user instead of using the DefaultCredentials.
      //NetworkCredential credential = new NetworkCredential("username", "password", "domain");
      //resolver.Credentials = credential;

      reader.XmlResolver = resolver;
      ...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups