1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / LoginStatus control and localization

LoginStatus control and localization

9 posts, 1 answered
  1. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    08 Mar 2010
    Link to this post
    Hi Ivan and co,

    I've come across a small problem that I can't work out how to get around.

    I use standard ASP.NET Forms authentication through the site, with the following configuration set up in Web.config:

    <authentication mode="Forms">
        <forms name=".ASPNET" loginUrl="~/signin.aspx" protection="All" timeout="1440" path="/" />
    </authentication>

    Using the LoginStatus control, this is no problem as the page redirects to the default language page which is ~/en/signin.aspx

    My problem comes when the user is in the Japanese version of the site. Whenever the user clicks on the LoginStatus control, it redirects to ~/signin.aspx which in turn redirects to the English language version of the page ~/en/signin.aspx

    I've looked up Microsoft documentation on the LoginStatus control and there appears to be no way to intercept where the control redirects to, to amend the localization prefix of "ja" to it.

    Can you suggest how I can get the LoginStatus control to take into account what the current language is?


    Regards,
    Alvaro
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Mar 2010
    Link to this post
    Hi Alvaro,

    You have to use LoginView control with templates instead of LoginStatus

    sample code

    <asp:LoginView ID="LoginView1" runat="server">
        <LoggedInTemplate>
        <p>
            <asp:LinkButton runat="server" ID="LogoutHyperLink" Text="Logout" />
             
        </p>
        </LoggedInTemplate>
        <AnonymousTemplate>
            <p>
                <asp:HyperLink runat="server" ID="LoginHyperlink" Text="Login" />
            </p>
        </AnonymousTemplate>
    </asp:LoginView>

    In the code behind you have to detect the current culture and redirect to the proper location

    public void Page_Load(object sender, EventArgs e)
    {
       
        HyperLink logStatus = LoginView1.FindControl("LoginHyperlink") as HyperLink;
        if (logStatus != null)
        {
            CultureInfo culture = CultureInfo.CurrentUICulture;
            if (culture.Name == "bg")
            {
                logStatus.NavigateUrl = "~/bg/LoginPage.aspx";
            }
            else
            {
                // somewhere else
            }
        }
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  3. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    08 Mar 2010
    Link to this post
    Hi Ivan,

    I am currently using the LoginView control with a LoginStatus control embedded in it, but I'll follow your advice and manually link the sign in control to my sign in page's url.

    Many thanks.

    Regards,
    Alvaro
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Mar 2010
    Link to this post
    Hi Alvaro,

    You can crate a separate control or tweak the existing one. In both cases this solution should work.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Pierre Alain
    Pierre Alain avatar
    38 posts
    Registered:
    10 Jun 2008
    23 May 2010
    Link to this post
    Hi,

    my understanding was that we could use DynamicHyperlink for something like this. When I drop a Dynamic Hyperlink on a page/template and set the NavigateUrl, it links to the proper localized version of the page when visited.

    However, when I try that in my own custom control, I can't get it to work:

    <sf:DynamicHyperLink ID="RegisterLink" runat="server" NavigateUrl="~/register.aspx" >Register</sf:DynamicHyperLink>

    Am I missing something? Am I wrong in thinking this should work?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 May 2010
    Link to this post
    Hi pacarrier,

    You should set the PageId property of the DynamicHyperLink control

    <script runat="server">
      
        protected void Page_Load(object sender, EventArgs e)
        {
            dhl.PageId = new Guid("25b53b78-135b-4708-9e3e-fd8d5c24ce09");
        }
    </script>
      
    <head runat="server">
        <title>Untitled Page</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />     
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
               ...
                <sfCms:DynamicHyperLink ID="dhl" runat="server">
                    <asp:Literal ID="LiteralFS" runat="server" Text="<%$Resources:FullStory %>"/>
                </sfCms:DynamicHyperLink>
                ...
       </form>
    </body>
    </html>


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Pierre Alain
    Pierre Alain avatar
    38 posts
    Registered:
    10 Jun 2008
    24 May 2010
    Link to this post
    Thank you. I figured it out last night.

    I also added a property to the custom control to access the DynamicLink from the CMS editor. On a regular control, it worked fine (I could click edit and assign a page), but the property of the DynamicLink were not saved.

    Then I try it on the LogiView control, adding a Register DynamicLink in the AnonymousTemplate. Now, I could not even access the DynamicLink properties. The textbox in the editor just said 'none'. I guess this is because I'm logged on and the AnonymousTemplate is not accessed, hence the control isn't instanciated.

    Any way to work around this?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 May 2010
    Link to this post
    Hi pacarrier,

    You could expose several properties and set them to DynamicHyperLink control inside OnPreRender

    protected override void OnPreRender(EventArgs e)
     {
         base.OnPreRender(e);
         DynamicHyperLink c = LoginView1.FindControl("dhl") as DynamicHyperLink;
         if(c !=null)
         c.PageId = test;
          
     }
     
     public Guid test
     {
         get
         {
             return this._test;
         }
         set
         {
             this._test = value;
         }
     }
     
     private Guid _test;
     private bool _destpge;


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Pierre Alain
    Pierre Alain avatar
    38 posts
    Registered:
    10 Jun 2008
    24 May 2010
    Link to this post
    Thank you.
Register for webinar
9 posts, 1 answered