XslCompiledTransform.Load Uri issues

Hi,

I'm playing with theXslCompiledTransform.Load method and having problems loading stylesheets.

First question - should you be able to specify a Uri as a server relative path? eg. /root/xsl/mydoc.xsl

I'm getting the following error loading with an absolute url...

System.Net.WebException: The remote server returned an error: (401) Unauthorized. 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.Xsl.Xslt.XsltLoader.CreateReader(Uri uri, XmlResolver xmlResolver) at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver) at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil) at System.Xml.Xsl.XslCompiledTransform.CompileToQil(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at System.Xml.Xsl.XslCompiledTransform.Load(String stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver)

However I can access the stylesheet fine through the broswer by specifying the same url? Any ideas what may be causing the 401.

[1704 byte] By [DonalMcWeeney] at [2007-12-26]
# 1

You have to use the Server.MapPath method to get the physical path corresponding to /root/xsl/mydoc.xsl. Also you may need to set the correct credentials for loading the stylesheet:

XslCompiledTransform trans = new XslCompiledTransform();
XmlUrlResolver resolver = new XmlUrlResolver();
// Set credentials for loading the stylesheet
resolver.Credentials = CredentialCache.DefaultCredentials;
trans.Load(Server.MapPath(
"MyStyle.xsl"), XsltSettings.Default, resolver);

Hope it helps,
Anton

-AntonLapounov at 2007-9-4 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified