Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Aug 22, 2011 @ 16:02
    Bjarne Fyrstenborg
    0

    Show only usercontrol for logged in member

    Hi..

    I have an usercontrol, which only must be available for logged in members. I guess there are several way to do this, e.g. place the macro inside a LoginView control.

    The have the content inside a asp:panel and then in page load only make it visible to logged in members

    protected void Page_Load(object sender, EventArgs e)
    {
        Member user = Member.GetCurrentMember();
        if (user != null)
        {
            SignupPanel.Visible = true;
        }
        else
        {
            SignupPanel.Visible = false;
        }
    }

    Or is there a better way to do this?

    Bjarne

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Aug 23, 2011 @ 12:06
    Bo Damgaard Mortensen
    0

    Hi Bjarne,

    Wouldn't it be enough to just place the macro within a loginview control on the template? :-)

    All the best,

    Bo

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Aug 23, 2011 @ 12:14
    Bjarne Fyrstenborg
    0

    Well, that is one way to do it..

    You can also check if the current member is null.. It works well this way and you only have to place the macro in the template..
    I think it would be the best way to do it this way, if it was a usercontrol, which is placed on several pages, where you don't have to place a loginview in several templates.

    Bjarne

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 23, 2011 @ 13:13
    Dirk De Grave
    2

    Bjarne,

    why not using

    SignupPanel.Visible = !HttpContext.Current.User.Identity.IsAuthenticated;

    Yours will work perfectly if you're using the built-in umbraco membership provider, as soon as you switch to another membership provider, your code will fail...

     

    Cheers,

    /Dirk

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Aug 23, 2011 @ 13:14
    Michael Latouche
    1

    Hi Bjarne,

    I'm not sure this is what you meant in your last post, but I guess you can just do the check in your user control itself. No need to have a loginview or panel in that case, just something like this in your user control Load or Init event:

    Visible=(Member.GetCurrentMember() != null);

    Cheers,

    Michael.

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Aug 23, 2011 @ 13:36
    Bjarne Fyrstenborg
    0

    Hi..

    Thanks for your suggestions... I guess there are several way of doing this, some might be better than other..

    I'm using the login to let the editors create members, who is allowed to signup for an event (employees can login and choose which events where they can work).
    Dirk, thanks for your suggestion... I think I only will be using the built-in umbraco membership provider.. but I guess I can use your code as well.

    I don't know how much difference the different code example means for the website in this case? But of course when I'm using a couple of lines, it will be better if it can be done in one code line.

    Bjarne

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Aug 23, 2011 @ 13:50
    Michael Latouche
    1

    Hi Bjarne,

    Dirk's suggestion for the check is more "generic", so i would use that one, you never know :-)

    For the "Visible" property part, it all depends on how you want to design your control. My suggestion was to just set the "Visible" property of the control itself, so you do not need to "encapsulate" it in a login view or in a panel. Just implement the control you need, and add the following line in its Load or Init event:

    Visible= HttpContext.Current.User.Identity.IsAuthenticated;

    That way, you do not have to worry where you put your control: it will always do the check.

    Cheers,

    Michael.

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Aug 23, 2011 @ 13:57
    Bjarne Fyrstenborg
    0

    Thanks Michael..

    Yes, I just placed it inside a panel, so I also could hide the surrounding div.. but I see in this way you suggest the usercontrol only is visible, when a member is logged in.

    It seem to I need a namespace for the HttpContext?

    Bjarne

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Aug 23, 2011 @ 14:06
    Michael Latouche
    1

    You need System.Web

    Cheers,

    Michael.

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Aug 23, 2011 @ 14:11
    Bjarne Fyrstenborg
    0

    Yep.. :)

    It works great :)

    Thanks
    Bjarne 

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Aug 23, 2011 @ 14:15
    Michael Latouche
    0

    No prob. Glad you got it working!

Please Sign in or register to post replies

Write your reply to:

Draft