XslTransform in .NET v1.1

G

George Durzi

I know this has changed greatly since v1.0. I'm converting a small portion
of my application where I do a transformation.
The error happens on this line:
oXslTransform.Load(XslPath + DataSourceName + ".xsl", oXmlUrlResolver);
ex.Message gives me: "Invalid Site"
ex.InnerException is empty

I've verified that XslPath + DataSourceName + ".xsl" is giving me the
correct path to the stylesheet in the format:

\\servername\e$\XslPath\StylesheetName.xsl

Here's my code

string ReportPath = ReportsFilePath + DataSourceName + TimePeriodSuffix
+ PreferredEmailFormat;
// Create a FileStream to write with
System.IO.FileStream oFileStream = new System.IO.FileStream(ReportPath,
System.IO.FileMode.Create);
// Create an XmlTextWriter for the FileStream
System.Xml.XmlTextWriter oXmlTextWriter = new
System.Xml.XmlTextWriter(oFileStream, System.Text.Encoding.Unicode);

try
{
// Create an XmlDataDocument from the ReportData DataSet parameter
XmlDataDocument oXmlDataDocument = new XmlDataDocument(ReportData);

// Set up the transformation
System.Xml.Xsl.XslTransform oXslTransform = new
System.Xml.Xsl.XslTransform();

// Load the Xsl and Transform
XmlUrlResolver oXmlUrlResolver = new XmlUrlResolver();
oXmlUrlResolver.Credentials = CredentialCache.DefaultCredentials;
oXslTransform.Load(XslPath + DataSourceName + ".xsl", oXmlUrlResolver);
// Xsl Path is class variable
oXslTransform.Transform(oXmlDataDocument, null, oXmlTextWriter,
oXmlUrlResolver);

// Close the XmlTextWriter object
oXmlTextWriter.Close();

return ReportPath;
}
catch (System.Exception ex)
{
oXmlTextWriter.Close();
System.IO.File.Delete(ReportPath);
throw (ex);
}
 
G

George Durzi

There must be some sort of rights issue. The code below works perfectly when
my Xsl is on a local drive, for example e:\Xsl\MyStyleSheet.Xsl

I get the "Invalid Site" error when my stylesheet is being referenced as
\\server\e$\Xsl\MyStyleSheet.Xsl
 
O

Oliver

It sounds like the UNC share doesn't know or recognize the ASPNET account or
whoever it is impersonating. You might want to check the permissions on the
share.
 
G

George Durzi

The ASPNET account has full control of the whole virtual directory and I am
still experiencing this error :(

Back to square one.
 
O

Oliver

But is ASP.NET impersonating someone who doesn't have rights... like the
IUSR_<machinename> account?
 
G

George Durzi

This is actually a Console application. Would Console applications also run
as the ASPNET account?
 
O

Oliver

Hi George,

I think a console application would run as the logged on user unless
configured to run as someone else.
 
G

George Durzi

I'm running the Console app on my machine in debug mode logged on with my
user id which is an enterprise admin on our domain.

When I point to my test Xsls locally on my machine (they're accessible at
e:\inetpub\wwwroot\MyApp\Xsl) everything runs fine. But when I switch to my
production Xsls accessible at \\server\e$\inetpub\etc ... I get that error.

I'll play around with it a little more tomorrow having it run under
different Ids. I'll post my success/failure here.

Amazing how this damn XmlResolver has turned 1 line of code into 5
 
B

Bret Mulvey [MS]

..NET 1.1 changed how XslTransform handles security. If I understand the docs
correctly, .NET 1.0 ran XSLT's (scripts embedded in XSLT's, access from
document() Xpath function, etc.) in a fully-trusted way. .NET 1.1 restricts
the level of trust by default. Remote files are less trusted than local
files, so you may be getting a security error because of that.

If you trust the remote XSLT, you give XsltTransform the same level of trust
as the calling assembly by passing this.GetType().Assembly.Evidence to the
evidence parameter of the Load method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top