Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edward Dudley 80 posts 121 karma points
    Oct 19, 2009 @ 12:10
    Edward Dudley
    0

    Query String Problems

    Hi,

    I'm trying to integrate the JW Image Rotator into my Umbraco website and having a bit of trouble.

    I have some XSLT which generates an RSS playlist that works fine when called directly.

    When JW Image Rotator calls the RSS feed it adds "?123" where 123 is a random number to the end of the URL and this causes an XSLT Error:

    <!-- Error generating macroContent: 'System.NullReferenceException: Object reference not set to an instance of an object.
    at umbraco.library.RenderTemplate(Int32 PageId, Int32 TemplateId)' -->

    It looks like RenderTemplate doesn't like this random number for some reason.

     

    A bit more info:

    My content structure:

    RSS Channel

    -- RSS Item

    -- RSS Item

    To get the RSS feed I do a GET to the RSS channel content node which has a template with a macro that uses RenderTemplate to render the templates of each of the child node RSS Items.

     

    Anyone else come across this or got any ideas how to fix it?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 19, 2009 @ 12:33
    Dave Woestenborghs
    0

    Hey,

     

    What is the code for you xslt macro and template. Because I just tried appending this querystring to one of my umbraco sites and it works fine.

     

    Dave

  • Edward Dudley 80 posts 121 karma points
    Oct 19, 2009 @ 14:39
    Edward Dudley
    0

    Hi,

    Thanks for the reply.  I think the problem is with the RenderTemplate function - it doesn't affect every page.

    To replicate this create the structure as shown in my first post in the content section.

    Each RSS Item should have a template.  The template for RSS Channel should contain a macro calling XSLT which contains the following:

    <xsl:for-each select="$currentPage/node">
                    <xsl:variable name="currentPageId" select="current()/@id" />
                    <xsl:value-of select="umbraco.library:RenderTemplate($currentPageId, current()/@template)" disable-output-escaping="yes"/>
    </xsl:for-each>

     

    Now navigate to the RSS Channel item in the content tree and append ?123 to the URL.  The RSS Item nodes will now no longer render correctly and will give the error above.

    (I've also tried the single argument version of RenderTemplate and had the same problem).

     

    Any ideas?  I've read that this random number has given other people trouble with PHP based CMSs.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 19, 2009 @ 15:17
    Dave Woestenborghs
    3

    I think the problem lies in the rendertemplate function. Reflector gives me this code for this function :

    public static string RenderTemplate(int PageId, int TemplateId)
    {
        try
        {
            if (UmbracoSettings.UseAspNetMasterPages)
            {
                if (!UmbracoContext.Current.LiveEditingContext.Enabled)
                {
                    HttpContext current = HttpContext.Current;
                    StringBuilder builder = new StringBuilder();
                    foreach (object obj2 in current.Request.QueryString.Keys)
                    {
                        if (!obj2.ToString().ToLower().Equals("umbpageid") && !obj2.ToString().ToLower().Equals("alttemplate"))
                        {
                            builder.Append(string.Format("&{0}={1}", obj2, current.Request.QueryString[obj2.ToString()]));
                        }
                    }
                    StringWriter writer = new StringWriter();
                    current.Server.Execute(string.Format("/default.aspx?umbPageID={0}&alttemplate={1}{2}", PageId, new template(TemplateId).TemplateAlias, builder), writer);
                    return writer.ToString();
                }
                return "RenderTemplate not supported in Canvas";
            }
            page page = new page(((IHasXmlNode) GetXmlNodeById(PageId.ToString()).Current).GetNode());
            page.RenderPage(TemplateId);
            Control pageContentControl = page.PageContentControl;
            StringWriter writer2 = new StringWriter();
            HtmlTextWriter writer3 = new HtmlTextWriter(writer2);
            pageContentControl.RenderControl(writer3);
            return writer2.ToString();
        }
        catch (Exception exception)
        {
            return string.Format("<!-- Error generating macroContent: '{0}' -->", exception);
        }
    }
    

    As you can see the function makes a call to your "Rss Item" with the given template. It also appends the querystring ("123")

    Maybe you can remove this querystring with UrlRewriting but I'm not an expert.

     

    Dave

  • Edward Dudley 80 posts 121 karma points
    Oct 19, 2009 @ 15:46
    Edward Dudley
    0

    Hmmm...

    So RenderTemplate doesn't like having unpaired things in the query string.

    I've not used URL rewriting either - is there anyone out there who could give me some simple instructions how I could rewrite the URL to remove this random number?

    Thanks

  • Alec Griffiths 129 posts 151 karma points
    Oct 19, 2009 @ 17:42
    Alec Griffiths
    0

    Ed if this is a bug you should submit it to codeplex.

  • Edward Dudley 80 posts 121 karma points
    Oct 19, 2009 @ 18:22
    Edward Dudley
    0

    On codeplex:

    http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=24967

    Any further suggestions still welcome though.

  • Alec Griffiths 129 posts 151 karma points
    Oct 19, 2009 @ 18:37
    Alec Griffiths
    0

    quite a horibal hack but perhaps you could you create an alt template that does the render template bit in your macro and get the default template to use GetXmlDocumentByUrl to call the same page with the alt template? Or write some also hacky c# to clear the qsring

  • Dennis Milandt 190 posts 517 karma points
    Nov 26, 2009 @ 18:06
    Dennis Milandt
    0

    I can confirm this error.

    I used RenderTemplate to render the HTML for a confirmation email at the url "www.blahblah.com?unsubscribe" <- RenderTemplate casts an exception when used on a url like this.

    Workaround was to redirect to another url and send the email from there.

    /Dennis

  • Edward Dudley 80 posts 121 karma points
    Dec 03, 2009 @ 12:21
    Edward Dudley
    1

    Thanks.

    Please vote on codeplex if this issue affects you!

     

    http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=24967

Please Sign in or register to post replies

Write your reply to:

Draft