Adding a schema to an XMLSchemaSet leads to 401 unauthorized  
Author Message
MrSandy





PostPosted: XML and the .NET Framework, Adding a schema to an XMLSchemaSet leads to 401 unauthorized Top

Hi there

I'm trying to execute the code in the following form:

XmlSchemaSet schemaSet = new XmlSchemaSet();

schemaSet.Add(" http://www.hide-link.com/ ;, "http://localhost/schemas/test.xsd");

The URL http://localhost/schemas exists on my local machine and is configured with Windows Authentication.

When I run this code from a console app or from a website I get a 401 (Unauthorised).

However, if I enable anonymous access, everything works perfectly.

Can anyone explain this



.NET Development22  
 
 
Jimmy Wu - MSFT





PostPosted: XML and the .NET Framework, Adding a schema to an XMLSchemaSet leads to 401 unauthorized Top

By configuring the virtual directory http://localhost/schemas to require Windows Authentication, every request to any files within that virtual directory will require proper user credentials, else you will get the 401 Unauthorized.

Looking at MSDN, under XmlSchemaSet.Add() topic there's the following comment:

Fully trusted code: A default XmlUrlResolver with no user credentials is used to resolve any external resources. The schemas for these other namespaces are loaded for validation purposes only. Unlike the original schema, these other schemas are not explicitly added to the schema collection. As a result, they are not accessible using any of the collection methods or properties. If these external resources are located on a network resource that requires authentication, use an overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

If you want to configure the virtual directory to require credentials, then use the XmlResolver overload instead of just specifying the URL as a string.

Jimmy