.net 4 xslt extension objects

I am updating the asp.net v3.5 web application. to v4, and I ran into some problems with XSLT transformations that I use for XmlDataSource objects.

Part of the XSLT file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ExtensionObject="ds:ExtensionObject"> 
  <xsl:output method="xml" indent="yes" encoding="utf-8"/> 
  <xsl:template match="/Menus"> 
    <MenuItems> 
      <xsl:call-template name="MenuListing" /> 
    </MenuItems> 
  </xsl:template> 

  <xsl:template name="MenuListing"> 
    <xsl:apply-templates select="Menu" /> 
  </xsl:template> 

  <xsl:template match="Menu"> 
      <MenuItem> 
        <xsl:attribute name="Text"> 
          <xsl:value-of select="ExtensionObject:HtmlEncode(MenuTitle)"/> 
        </xsl:attribute> 
        <xsl:attribute name="ToolTip"> 
          <xsl:value-of select="MenuTitle"/> 
        </xsl:attribute> 
      </MenuItem> 
  </xsl:template> 
</xsl:stylesheet> 

And this is the initialization:

xmlDataSource.TransformArgumentList.AddExtensionObject("ds:ExtensionObject", new ExtensionObject()); 
xmlDataSource.Data = Cache.FetchPageMenu(); 

ExtensionObject:

public class ExtensionObject {
    public static string HtmlEncode(string input) {
        return "test";
    } 
}

I asked a similar question before: .net 4 xslt transform The extension function is broken . The answer was right about the ambiguous call, but even with another correct object, it simply won’t work. I do not get any errors, just the data is not displayed.

I also tried this:

static void test() {
    // Create the XslCompiledTransform and load the stylesheet.
    XslCompiledTransform xslt = new XslCompiledTransform(true);
    xslt.Load(System.Web.Hosting.HostingEnvironment.MapPath("~/transforms/menu.xslt"));

    // Create an XsltArgumentList.
    XsltArgumentList xslArg = new XsltArgumentList();
    xslArg.AddExtensionObject("ds:ExtensionObject", new ExtensionObject());

    using (XmlWriter w = XmlWriter.Create("output.xml")) {
        // Transform the file.
        xslt.Transform(Cache.FetchPageMenu(), xslArg, w);
    }
}

This works correctly in a console application, but in a web application I get a security exception, without any further details;

[SecurityException: .]
System.RuntimeMethodHandle.PerformSecurityCheck( obj, RuntimeMethodHandleInternal , RuntimeType parent, UInt32 invocationFlags) +0
System.Reflection.RuntimeMethodInfo.Invoke( obj, BindingFlags invokeAttr, Binder , Object [], CultureInfo, Boolean skipVisibilityChecks) +323
System.Reflection.RuntimeMethodInfo.Invoke( obj, BindingFlags invokeAttr, Binder , Object [], ) +38
System.Reflection.MethodBase.Invoke( obj, Object []) +35
System.Xml.Xsl.XsltOld.FuncExtension.Invoke(XsltContext xsltContext, Object [] args, XPathNavigator docContext) +164
MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) +430

asp.net v4 IIS7 .

ExtensionObjects. , , xslt ?

agian..

+3
1

...

: .Net 4

[: SecurityRules (SecurityRuleSet.Level1)] .

+5

Source: https://habr.com/ru/post/1758385/


All Articles