More in this section

Forums / Developing with Sitefinity / Problems with Login Custom Control

Problems with Login Custom Control

4 posts, 0 answered
  1. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    02 Dec 2011
    Link to this post
    First, let me say that I really like Sitefinity.  There are however, a number of very basic things are really lacking.  The frontend user account management widgets kinda suck.  Just about every website I visit has functionality that allows a user to register, login, retreive or reset thier password, change thier password, etc.  SF only includes "Login", "Login name", and "Log in / log out button" widgets.  To make matters worse, there's something broken with the designer that prevents the "LoggedInLayoutTemplatePath" and "LoggedOutLayoutTemplatePath" settings from being persisted and from what I can tell it's been broken for a long time. 

    So the only real option is to roll my own which should be simple enough.  Should be, but I've run into a strange problem.  Below are my template mark up and control code:

    Template:
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="sf" %>
    <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
     <AnonymousTemplate>
      <asp:HyperLink ID="LoginLink" runat="server" NavigateUrl="~/login" CssClass="loginContainerLoginLink">Log In</asp:HyperLink>
     </AnonymousTemplate>
     <LoggedInTemplate>
      <ul id="loginStatus">
       <li class="loginContainerYourAccount">
        <asp:LinkButton ID="YourAccountLinkBtn" runat="server" Text="Your Account" CssClass="loginContainerYourAccountLink" />
       </li>
       <li class="loginContainerLogout">
        <asp:LinkButton ID="LogOutLinkBtn" runat="server" Text="Log Out" CssClass="loginContainerLogoutLink" />
       </li>
      </ul>
     </LoggedInTemplate>
    </asp:LoginView>

    Code:
    using Telerik.Sitefinity.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity.Security;
    using System.Web.UI;
    namespace SitefinityWebApp.CustomControls
    {
    public class LoginStatusWidget : SimpleView
    {
    #region Properties
    protected override string LayoutTemplateName
    {
    get { return "SitefinityWebApp.CustomControls.Resources.Views.LoginStatusWidget.ascx"; }
    }
    #endregion
    protected override void InitializeControls(GenericContainer container)
    {
    EnsureChildControls();
    LinkButton logOutLinkBtn = base.Container.GetControl<LinkButton>("LogOutLinkBtn", false); ;
    LinkButton yourAccountLinkBtn = base.Container.GetControl<LinkButton>("YourAccountLinkBtn", false);
    if(logOutLinkBtn != null)
    logOutLinkBtn.Click += new System.EventHandler(OnLogOutLinkBtnClick);
    if (yourAccountLinkBtn != null)
    yourAccountLinkBtn.Click += new System.EventHandler(OnYourAccountLinkBtnClick);
    }
    void OnYourAccountLinkBtnClick(object sender, System.EventArgs e)
    {
    this.Page.Response.Redirect("~/user/your-account");
    }
    void OnLogOutLinkBtnClick(object sender, System.EventArgs e)
    {
    SecurityManager.Logout();
    SecurityManager.DeleteAuthCookies();
    this.Page.Response.Redirect("~/");
    }
    }
    }

    The problem is that
    base.Container.GetControl<LinkButton>("LogOutLinkBtn", false);
    and base.Container.GetControl<LinkButton>("YourAccountLinkBtn", false);

    always return null.  I've tried looking for the control a number ways but the result is always null.  Is there something different I need to do to find control in a LoginView / AnonymousTemplate / LoggedInTemplate?

    Thanks--Steve
  2. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    03 Dec 2011
    Link to this post
    Well, I've spent hours of trying to get this to work with absolutely no progress.  Googling turns up a large number of posts on the subject an the common strategy is to find first the LoginView control and then call the LoginView's FindControl method.  The problem is that I can't find the LoginView.

    Ironically, if I move the controls outside of <LoggedInTemplate></ LoggedInTemplate> tags I can find the controls with no problem.

     Does anyone have any ideas here?

    Thanks--Steve
  3. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    03 Dec 2011
    Link to this post
    Just a quick post to close this out in case someone else runs into the same type of problem.  This is a case where creating a custom control that inherits from SimpleView is a bad idea.  I spent hours trying to make this work without success.  I finally decided to make this into a standard ASP.net WebUserControl and had it coded, working, and registered in 15 minutes from start to finish.

    --Steve
  4. Info
    Info avatar
    4 posts
    Registered:
    25 Nov 2012
    22 Feb 2013 in reply to SteveV
    Link to this post

    Hi, do you have a post where you explain how you solved it. I am using my own web user controls with Login, LoginView and Register.  

    Currently I have the problem that the LoginView control is not refreshed. This is because the page itself is cached. Disable the cache for the page solves the problem, but somehow I think that it is not wise. Since the LoginView appears on the header of each page, this would mean I cannot cache a single page and thus creating a performance leak. How do you handle your LoginView control?

4 posts, 0 answered