More in this section

Forums / Developing with Sitefinity / Login page does not redirect back to forum

Login page does not redirect back to forum

4 posts, 0 answered
  1. Simon
    Simon avatar
    14 posts
    Registered:
    26 Jul 2008
    20 Oct 2009
    Link to this post
    Hello

    I have a custom login page with a login control on it.

    When someone who is not logged in goes to the try and create a forum post they get directed to this login page. When the person logs in I expect them to get sent back to the forum but they don't they end up on the same page.

    How do I fix that?

    Regards

    Simon
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Oct 2009
    Link to this post
    Hello Simon,

    You should add the return url as a QueryString. Thus the control will know where the send the request after you have authenticated yourself.

    Sample code (Login control code behind):

    void Page_Load(object sender, EventArgs e)
        {
            this.Login1.LoggedIn += new EventHandler(Login1_LoggedIn); 
        }
      
      
        
        void Login1_LoggedIn(object sender, EventArgs e)
        {
            HttpCookie cookie = this.Response.Cookies[FormsAuthentication.FormsCookieName];
            UserManager.Default.SetAuthenticationCookie(cookie);
            string redirectUrl = Request.QueryString["ReturnUrl"];
            if (string.IsNullOrEmpty(redirectUrl))
            {
                redirectUrl = this.Login1.DestinationPageUrl;
            }
            else
            {
                redirectUrl = HttpUtility.UrlDecode(redirectUrl);
            }
     
            this.Page.Response.Redirect(redirectUrl, true);
        }

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Simon
    Simon avatar
    14 posts
    Registered:
    26 Jul 2008
    25 Oct 2009
    Link to this post
    How do I add code to a Page I've created with the CMS, or do I have to do it outside of the CMS.

    If so thats a shame as I loose all the master page and themeing.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Oct 2009
    Link to this post
    Hello Simon,

    You should add the logic to the code behind of your logic control
    "Sample code (Login control code behind):"

    If you use the built in Login control you will find its declaration and code behind under Sitefinity/UserControls/Login folder.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered