Embedded xslt calling resources  
Author Message
Dat23





PostPosted: XML and the .NET Framework, Embedded xslt calling resources Top

Hello, I am having an issue in using an embedded xslt in a dll when a part of that xslt is calling an extension object which uses an external resource. My xslt code is as follows

<xsl:stylesheet version="1.0" xmlns:xsl=" http://www.hide-link.com/ ;

xmlns:mapUtil="urn:mapUtil" extension-element-prefixes="mapUtil">

<!-- some other xslt stuff but below is the main part -->

<xsl:variable name="primaryIndex" select="mapUtil:GetCategoryInformation($Id, 'PrimaryIndex', 'true')"/>

The GetCategoryInformation method inside the MappingUtility object calls a stored procedure. When I try to run this through, I get a

"Request for the permission of type System.Data.SqlClient.SqlClientPermission ... " error.

I am embedding the xslt into the dll at compile time as follows. Reason that we are embedding the xslt are for security reasons and ease of deployment. If I load the xslt at runtime using the commented out code, it works though..

Any help would be appreciated.... Thanks

XmlUrlResolver_resolver = new XmlUrlResolver();

System.Security.Policy.Evidence _evidence = new System.Security.Policy.Evidence();

XsltArgumentList _argsList = new XsltArgumentList();

MappingUtility util = new MappingUtility();

_argsList.AddExtensionObject("urn:mapUtil", util);

// This works but does not embed the xslt at compile time

// _transFund = new XslTransform();

// _transFund.Load(xsltFund, _resolver);

// Embed the xslt but it does not work for some security permission reasons

string xsltFund = "SolutionXmlPackage.Mapping21.xslt.Fund.xslt";

_transFund = new XslTransform();

_transFund.Load(new XmlTextReader(

GetType().Assembly.GetManifestResourceStream(xsltFund)),

_resolver, _evidence);



.NET Development30  
 
 
Marcelo - MSFT





PostPosted: XML and the .NET Framework, Embedded xslt calling resources Top

The permissions are calculated at .Load time. According to http://msdn2.microsoft.com/en-us/library/50ste364.aspx, you will need to supply the appropriate _evidence when you call the overload with three arguments. In this case, it appears that this.GetType().Assembly.Evidence might be the appropriate choice.

Please let me know whether this sets you on the right track.

Thanks,

Marcelo - MSFT


 
 
Dat23





PostPosted: XML and the .NET Framework, Embedded xslt calling resources Top

Yes, thanks much, it worked. Apparently, I was only using a new empty Evidence object rather than using the current Assembly's evidence...