I’d like to know the sub status code of the 401 error you encountered. The 401 error contains the following sub status code:
401.1: Access is denied due to invalid credentials.
401.2: Access is denied due to server configuration favoring an alternate authentication method.
401.3: Access is denied due to an ACL set on the requested resource.
401.4: Authorization failed by a filter installed on the Web server.
401.5: Authorization failed by an ISAPI/CGI application.
401.7: Access denied by URL authorization policy on the Web server.
Because the project works well on your machine, I doubt it is a process identity issue. By default the application pool in IIS 6.0 uses “Network Service” as its identity. This account is restricted, so that you may encounter access deny issue.
For troubleshooting purpose, please try to change the application pool’s identity to “Local System”. If this method can resolve the issue, change back the identity to “Network Service”, and grant read/write permission to the xml file you want to read/write.
About how to change application pool’s identity, please refer to the following steps:
1. Open IIS manager (Start | Control Panel | Administrative Tools | Internet Information Services Manager).
2. Expand the “Application Pools” node.
3. Right click the application pool which your project is using, and then select “Properties”.
4. Click “Identity” tab.
5. Choose “Local System” in the Predefined dropdown list.
About how to grant permission to a file, please check these steps:
1. Open Windows Explorer.
2. Right click the file, and then select "Properties".
3. Click the "Security" tab.
4. Add "Network Service" in access list and check "Modify", "Read", and "Write" for it.
In addition, other files may cause this issue too, you can use Filemon to monitor any access file deny issues.
Sincerely,
Benson Yu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
I'm also having the same problem as the original poster. If the web site is set up as anonymous then everything works fine but as soon as I change it to Integrated Windows authentication I receive a 401 on this line of code:
I have tried granting "everyone", my ID, "Network Service", and the "SYSTEM" account full control to the web site and this XSD file through file explorer but to no avail. I've run filemon and it is showing no failures and the security event log is also
showing no failures.
I've attached a sample error message along with some sample code. I'm a bit stumped at the moment and would appreciate some advice! Thx. John.
Error Message:
Exception Type: System.Net.WebException
Status: ProtocolError
Response: System.Net.HttpWebResponse
Message: The remote server returned an error: (401) Unauthorized.
Data: System.Collections.ListDictionaryInternal
TargetSite: System.Net.WebResponse GetResponse()
HelpLink: NULL
Source: System
StackTrace Information
*********************************************
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, String schemaUri)
at PreventionDocument.ValidateDocumentAgainstSchema() in C:\DotNetProjects\SchemaURLTester\App_Code\Default.aspx.vb
Source Code Sample:
Try
Dim readerSettings As New System.Xml.XmlReaderSettings()
Dim revolver As New System.Xml.XmlUrlResolver()
revolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
readerSettings.XmlResolver = revolver
readerSettings.ValidationType = System.Xml.ValidationType.Schema
readerSettings.Schemas.Add(Nothing, "http://localhost/schemaURLTester/XSD/myTest.xsd")Catch ex As Exception
Return ex.Message
End Try
I might be late in replying this. But this may be useful for any of those who have this problem later on.
On IIS, Application pools run on 'Network Service' account. So, give permissions for this account on the ASP.Net Temp folder. This will solve the problem
i m trying to scrap website but some webiste ues windows authentication. below code works fine for one of the webiste which i used as windows authentication but on other website i m getting below error. please help. thanks
Error
The remote server returned an error: (401) Unauthorized.
VB.NET code:
Dim username As String = ""
Dim password As String = ""
Dim req As New WebClient()
Dim results As String
Dim myCache As New CredentialCache()
myCache.Add(New Uri("URL"), "Basic", New NetworkCredential(username, password))
rbissa
0 Points
1 Post
The remote server returned an error: (401) Unauthorized (ASP.net2005)
Oct 02, 2007 09:26 AM|LINK
Hi, I have other error occuring when migrating from ASp.net 2003 to ASP.net 2005. it is related to XmlReader.
here is my code: Code Block
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
//System.Net.NetworkCredential nc = new System.Net.NetworkCredential();
resolver.Credentials = nc;
// Create the reader. XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = resolver;
XmlReader ReaderObj = XmlReader.Create(szResourceXml);
while(ReaderObj.Read()) { }
It is working fine on my local machine. When i deploy it to the server (Window 2003 server) i am getting the following error:
The remote server returned an error: (401) Unauthorized
Thanks,
Rania
Benson Yu - ...
All-Star
34797 Points
2497 Posts
Re: The remote server returned an error: (401) Unauthorized (ASP.net2005)
Oct 05, 2007 02:52 AM|LINK
Hi Rania,
I’d like to know the sub status code of the 401 error you encountered. The 401 error contains the following sub status code:
401.1: Access is denied due to invalid credentials.
401.2: Access is denied due to server configuration favoring an alternate authentication method.
401.3: Access is denied due to an ACL set on the requested resource.
401.4: Authorization failed by a filter installed on the Web server.
401.5: Authorization failed by an ISAPI/CGI application.
401.7: Access denied by URL authorization policy on the Web server.
Because the project works well on your machine, I doubt it is a process identity issue. By default the application pool in IIS 6.0 uses “Network Service” as its identity. This account is restricted, so that you may encounter access deny issue.
For troubleshooting purpose, please try to change the application pool’s identity to “Local System”. If this method can resolve the issue, change back the identity to “Network Service”, and grant read/write permission to the xml file you want to read/write.
About how to change application pool’s identity, please refer to the following steps:
1. Open IIS manager (Start | Control Panel | Administrative Tools | Internet Information Services Manager).
2. Expand the “Application Pools” node.
3. Right click the application pool which your project is using, and then select “Properties”.
4. Click “Identity” tab.
5. Choose “Local System” in the Predefined dropdown list.
About how to grant permission to a file, please check these steps:
1. Open Windows Explorer.
2. Right click the file, and then select "Properties".
3. Click the "Security" tab.
4. Add "Network Service" in access list and check "Modify", "Read", and "Write" for it.
In addition, other files may cause this issue too, you can use Filemon to monitor any access file deny issues.
FileMon for Windows v7.04
http://www.microsoft.com/technet/sysinternals/FileAndDisk/Filemon.mspx
Benson Yu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
jkmclean
Member
2 Points
1 Post
Re: The remote server returned an error: (401) Unauthorized (ASP.net2005)
Dec 18, 2007 11:43 PM|LINK
I'm also having the same problem as the original poster. If the web site is set up as anonymous then everything works fine but as soon as I change it to Integrated Windows authentication I receive a 401 on this line of code:
readerSettings.Schemas.Add(Nothing, "http://localhost/schemaURLTester/XSD/myTest.xsd")
I have tried granting "everyone", my ID, "Network Service", and the "SYSTEM" account full control to the web site and this XSD file through file explorer but to no avail. I've run filemon and it is showing no failures and the security event log is also showing no failures.
I've attached a sample error message along with some sample code. I'm a bit stumped at the moment and would appreciate some advice! Thx. John.
Error Message:
sandeepbhuta...
Participant
1419 Points
375 Posts
Re: The remote server returned an error: (401) Unauthorized (ASP.net2005)
Sep 01, 2008 11:10 AM|LINK
Hi,
I have the same issue. But I am not able to see the sub status code. can you please tell me where to see the substatus code? which property to refer?
thx
Sandeep Bhutani
nandakishore...
Member
2 Points
1 Post
Re: The remote server returned an error: (401) Unauthorized (ASP.net2005)
Sep 22, 2008 05:09 AM|LINK
I might be late in replying this. But this may be useful for any of those who have this problem later on.
On IIS, Application pools run on 'Network Service' account. So, give permissions for this account on the ASP.Net Temp folder. This will solve the problem
sumit_upadhy...
Member
18 Points
9 Posts
Re: The remote server returned an error: (401) Unauthorized (ASP.net2005)
Jul 15, 2009 12:53 PM|LINK
Hello all,
i m trying to scrap website but some webiste ues windows authentication. below code works fine for one of the webiste which i used as windows authentication but on other website i m getting below error. please help. thanks
Error
The remote server returned an error: (401) Unauthorized.
VB.NET code:
Dim username As String = ""
Dim password As String = ""
Dim req As New WebClient()
Dim results As String
Dim myCache As New CredentialCache()
myCache.Add(New Uri("URL"), "Basic", New NetworkCredential(username, password))
results = System.Text.Encoding.UTF8.GetString(req.DownloadData("URL"))
trivediD
Member
6 Points
3 Posts
Re: The remote server returned an error: (401) Unauthorized (ASP.net2005)
Nov 14, 2009 03:18 AM|LINK
make sure you specify guid for listname not the "name" . i had this problem and went away after i used GUID