Copied to clipboard

Flag this post as spam?

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


  • Bram Loquet 72 posts 102 karma points
    Nov 17, 2010 @ 09:06
    Bram Loquet
    0

    don't get my node back with linq after response.redirect

    With this code I just create a new umbraco node (OrderDocType) and refresh the current page,
    after the response.redirect I try to get my order back with linq.

    When I do so I don't get my node back until I hit F5.
    Does anybody know how to solve this problem?

            protected void Page_Load(object sender, EventArgs e)
    {
    if (Request["product"] != null)
    {
    var orderNr = DateTime.Now.ToString("yyyyMMdd") + "-" + StringHelper.TruncString(Guid.NewGuid().ToString().Replace("-", ""), 20, false);
    var docOrder = DocumentType.GetByAlias("OrderDoctype");
    var newOrder = Document.MakeNew(orderNr, docOrder, new User(0), 1234);
    newOrder.getProperty("orderNr").Value = orderNr;
    newOrder.Publish(admin);
    library.UpdateDocumentCache(newOrder.Id);

    CookieHelper.AddCookie("OrderNr", orderNr);

    var current = Node.GetCurrent();
    Response.Redirect(current.NiceUrl);
    }
    else
    {
    if (CookieHelper.GetCookie("OrderNr") != null)
    {
    var orderNr = CookieHelper.GetCookie("OrderNr");
    _ctx = new WebsDataContext();
    var order = (from o in _ctx.OrderDoctypes
    where o.OrderNr == orderNr
    select o).First();
    _ctx.Dispose();
    }
    }
    }

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 17, 2010 @ 12:48
    Aaron Powell
    0

    I can't remember if the publishing is async, if that's the case it may be a problem, that's the only thing I can think could be a problem. 

    But TBH I haven't tried doing what you're doing so I haven't had that problem arise. 

    Does it exist if you go via NodeFactory?

  • Bram Loquet 72 posts 102 karma points
    Nov 17, 2010 @ 13:20
    Bram Loquet
    0

    Thx for your reply.

    The problem is that use a specific id (OrderNr) to get the order instead of the id of the node so working with the NodeFactory is a bit diffcult I think.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 17, 2010 @ 13:52
    Aaron Powell
    1

    How about trying to access it through umbraco.library and an XPath statement there.

  • Bram Loquet 72 posts 102 karma points
    Nov 22, 2010 @ 09:59
    Bram Loquet
    0

    Will do it with XPath.

    Find it a bit strange it seems that I'm the onlyone using Linq & the Datacontext this way but at least we have wa way around it.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 02, 2010 @ 16:27
    Jeroen Breuer
    0

    Hi Slace,

    I've also had this problem when I was having my level 2 course with Per Ploug. Thought that he sent you an email about this. Guess not...

    It doesn't happen with the nodeFactory.

    Hope this can be fixed for 4.6.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 02, 2010 @ 17:02
    Jeroen Breuer
    0

    I've also added a workitem for it: http://umbraco.codeplex.com/workitem/29632.

    Jeroen

  • Bram Loquet 72 posts 102 karma points
    Dec 02, 2010 @ 17:05
    Bram Loquet
    0

    @Jeroen, you got my vote.

  • kristian schneider 190 posts 351 karma points
    Dec 19, 2011 @ 17:20
    kristian schneider
    1

    I think I can explain what is going on.

    the umbracodatacontext reads from the umbraco.config xml file. And if you look at the following comment in umbraco.content.QueueXmlForPersistence()

    /// <summary>
            /// Marks a flag in the HttpContext so that, upon page execution completion, the Xml cache will
            /// get persisted to disk. Ensure this method is only called from a thread executing a page request
            /// since umbraco.presentation.requestModule is the only monitor of this flag and is responsible
            /// for enacting the persistence at the PostRequestHandlerExecute stage of the page lifecycle.
            /// </summary>
     private void QueueXmlForPersistence()
            {
                /* Alex Norcliffe 2010 06 03 - removing all launching of ThreadPool threads, instead we just 
                 * flag on the context that the Xml should be saved and an event in the requestModule
                 * will check for this and call PersistXmlToFile() if necessary */
               

    So the XML is not updatede until the the end of the page request and therefore you don't get an updated umbracodatacontext until next time the page is loaded

     

Please Sign in or register to post replies

Write your reply to:

Draft