Copied to clipboard

Flag this post as spam?

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


  • Arnt Grøstad 29 posts 49 karma points
    Nov 26, 2010 @ 18:28
    Arnt Grøstad
    0

    umbraco to fast for my C# code?

    Hi.
    I usually uses usercontrols for stuff inside contentplaceholders.
    And now I face a problem I never thought I would experience :)

    Here we go:

    In my MasterPage I register an usercontroler eg "desktopheader.ascx".
    In the .ascx I have my rel links to different JavaScript, meta generators and so on.
    Ok.
    I also hav a rel link to the .css file. I have different .css files, depent on who is the Currently Logged In Member.

    I do this by code:
     <link rel="stylesheet" type="text/css" href="<%=GetStylesheet()%>" />

    And in code-behind I have a protected string function that checks up currentuser and return a string that could be:
    "/css/user1/styles.css"
    or
    "/css/user10/styles.css"

    Ok, this works fine.....sometimes.
    When using the site, cliking the menu, have a cup of coffee, clicking some more, I suddently loose the css-path. The css collapses. Pressing wonderfull F5 get's it back on track for some times. Then I loose it again.

    More info:
    I have also tried to put the css-string from the proteced function in the web.cache and read's it from there, but no luck. Still looses my css path now and then.

    This is the same function I use in other website/cms (as EPiserver), but Umbraco works to fast for my code-behind code.
    It looks like the page is parsed and given to the client browser long before the function is handled by the server :)


    Any...and I really mean..Any ideas?


  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 27, 2010 @ 01:21
    Lee Kelleher
    0

    Hi Arnt,

    Firstly, it wont be that Umbraco is too fast for your code.  Your user-control is part of the ASP.NET page life-cycle, so your code will be hit when it needs to be hit - its not going to be skipped over.

    I'm curious what the code/logic is within the GetStylesheet() method.  My feeling is that however you are accessing the member/user data, its not consistent? (that's just a wild guess).  If you could provide more details on GetStylesheet() we might be able to help?

    Thanks, Lee.

  • Arnt Grøstad 29 posts 49 karma points
    Nov 27, 2010 @ 09:35
    Arnt Grøstad
    0

    Im sure you are right, Lee.
    Beeing over this method a lot's of times with my debugger running, but can't seem to find my "jiffy".
    This seems to relay on my C# skills (doh), and it's NOT an Umbraco issue. And im not asking you guys to be my debugger, but do really appreciate the tips.

    Here goes:

     

     

     

    /// <summary>

     

     

    /// Gets the style sheet from user startpage for supplied stylesheet key

     

     

    /// </summary>

     

     

    protected string GetStyleSheet(string styleSheet)

    {

     

     

    try

    {

     

     

    //Get user start page

    IQWDT2011.Util.

     

    CurrentUser currentUser = IQWDT2011.Util.CurrentSettings.GetCurrentUser();

     

     

    //Get style sheet

     

     

    return ResolveUrl(currentUser.GetStyleSheet(styleSheet));

    }

     

     

    catch

    {

     

     

    return "";

    }

    }

     

    So, looking into GetCurrentUser();
    Remeber my comments, we are usually using a SignUp Site that validates the user by 2-factor login, and ISA redirects the user to correct site if valid with CurrentUserInfo in Session. But for development we just hardcode user credentials in global.asax Application_Start. Heres the CurrentSettings class with GetCurrentUser() method

    public static CurrentUser GetCurrentUser() 
    {
    if (HttpContext.Current.Session["CurrentUser"] != null && HttpContext.Current.Session["CurrentUser"] is CurrentUser)
    {
    return HttpContext.Current.Session["CurrentUser"] as CurrentUser;
    }
    else
     {
    CurrentUser cu = new CurrentUser();
    HttpContext.Current.Session["CurrentUser"] = cu;
    return cu;
    }


     

     

     

     

     

    Ok, we got a CurrentUser.
    Let's go back to GetStyleSheet() and really bring out the sheets :)
    Remeber the GetStyleSheet on top of this post. When having the CurrentUser, it vil do a

     ResolveUrl(currentUser.GetStyleSheet(styleSheet));
     Let's do a dive into that:

     

     

     //currentUSer.GetStyleSheet 
    public string GetStyleSheet(string styleSheet) //styleSheet beeing f.ex "Webdesktop"

    try

    {

     

     

    XmlNode myNode = UserStartNode; //UserStartNode returns an XmlNode based on CurrentUser's cred's and properties value.

     

     

    string strAlias = "styleSheet" + styleSheet;

     

     

    if (myNode.SelectSingleNode(strAlias).InnerText != null && myNode.SelectSingleNode(strAlias).InnerText.ToString() != "")

     

     

    return myNode.SelectSingleNode(strAlias).InnerText; //Should now give you the value /css/group8/group8.css - or whatever value that are in this alias/property 

     

     

    else

     

     

    return "";

    }

     

     

    catch { }

     

     

    return "";

    }


       
    So, this maybe just made this post worse, and maybe the explanation of the code is far fetched, but uf you see anything really Home Simpson dumb code, please let me know.

  • Arnt Grøstad 29 posts 49 karma points
    Nov 27, 2010 @ 09:47
    Arnt Grøstad
    0

    Woopdi doo.
    Seems as I can't format my code in this editor even.
    Maybe have a break, and re-think my issues :)

  • Arnt Grøstad 29 posts 49 karma points
    Nov 27, 2010 @ 10:18
    Arnt Grøstad
    0

    Ok writing the code in this forum, make me realise that depending on:

    public

     

     

    string GetStyleSheet(string styleSheet)

    {

     

     

    try

    {

     

     

    XmlNode myNode = UserStartNode;

     

     

    string strAlias = "styleSheet" + styleSheet;

     

     

    if (myNode.SelectSingleNode(strAlias).InnerText != null && myNode.SelectSingleNode(strAlias).InnerText.ToString() != "")

     

     

    return myNode.SelectSingleNode(strAlias).InnerText;

     

     

    else

     

     

    return "";

    }

     

     

    catch { }

     

     

    return "";

    }


    was a bit to hasty. I know se that this function thows a cath know and then.
    cool, found the jiffy, I'll probably find out why pretty soon.

  • Arnt Grøstad 29 posts 49 karma points
    Nov 28, 2010 @ 09:43
    Arnt Grøstad
    0

    Hmmm, first of all.
    Lee: sorry to waste your time.
    I found my jiffy.
    The GetStyleSheet() method ask for userStartNode and itself triggers an assembly that do some funny stuff towards the db and AD.
    When getting the userStartNode, it will put it in the HttpContext.Cache. This Cache get's the expiration time from a web.config appsettings key. Guess what.
    The key did'nt exist i the web.config. So the object faild, and faild and worked, and fail, and fail, and worked.

    The devil truly lies in the details.

    Thanks Lee for forcing me to actually use my 2 braincells :)
    Thanks :)

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 28, 2010 @ 10:02
    Lee Kelleher
    0

    Hi Arnt,

    No need to apologise, not a waste of time at all. I'm happy to help where I can... even if that's pointing you in the right direction.

    Glad that you figured it out!

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft