The remote server returned an error: (401) Unauthorized.
-
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 -
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 - EvanHi there, I think that you are trying to access an xml file at
line 387
in thewogrid.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;
...