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

Forums / Security / login redirection

login redirection

15 posts, 0 answered
  1. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    24 Aug 2010
    Link to this post
    Hi Team,

    I´m trying to get the following to work. When a user clicks on the full story button I want them to be redirected to my login page(if they are not logged in) and if they provide the right credentials I want them to be redirected to the full story that they clicked on. Is there a way to achive this?

    Thanks
    Johnny
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Aug 2010
    Link to this post
    Hi Johnny,

    Create a custom control that inherits from the ContentView based control you use. Override SetItemMetadata there. From the itemContainer parameter find fullContent url. Use UserManager.GetCurrentUser() to identify whether there is a valid user. If not redirect them to your login page. The url of the login page could be exposed as a public property which will allow you to set it through control designer later.
    The ASP.NET login control has ReturnUrl querystring that you can use to redirect the authenticated user back the the same article.

    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
  3. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    24 Aug 2010
    Link to this post
    Hello Ivan!

    I´ve got 2 questions for you. How can I get the full content url and how can I make use of it in the login control?

    Johnny
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Aug 2010
    Link to this post
    Hi Johnny,

    SetItemMetadata method has a parameter contentItem from where you can get the content item url. The IContent object has a property UrlWithExtension.  Here is a related article -Getting your News articles full Urls
    As for the ASP.NET Login control, the server looks for an authentication cookie. If it fails to find the authentication cookie, the user is redirected to the configured logon page (Login.aspx), as specified by the LoginUrl attribute of the forms element. The user supplies and submits credentials through this form. Information about the originating page is placed in the query string using RETURNURL as the key.  You can explicitly force setting the QueryString in the url and the Login control will read it automatically.

    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
  5. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    30 Aug 2010
    Link to this post
    Hello,

    So I have my custom content view and I´m performing a check to see if the user is logged in or not.
    protected override void SetSingleItemContent(Telerik.Cms.Engine.IContent item)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                base.SetSingleItemContent(item);
            }
            else
            {
                System.Web.HttpContext.Current.Response.Redirect("~/Login.aspx");
            }
        }
    My problem is still what to do with the actual redirect when a user click´s full story. Anyone else who have made this work and would like to drop some knowledge on me?

    Thanks
    Johnny
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Aug 2010
    Link to this post
    Hello Johnny,

    My problem is still what to do with the actual redirect when a user click´s full story.

    You have to alter the fullContent url. Override SetItemMetadata and get the control with id that equals to fullContent + i where i is between 1 and 6. Then cast the control to a HyperLink and set its NavigateUrl property depending on whether the user has been logged in or not.

    Best wishes,
    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. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    02 Sep 2010
    Link to this post
    I still can´t get this to work properly. I have gone trough a lot of forum post´s and I think I´m in the right direction but now I´m beeing redirected to login when I go to the page it self and not when I click on the full story link. Is there some other code snippets around?

    public class TeasersContentView : ContentView
    {
        protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
      
            for (int i = 1; i < 6; i++)
            {
                var ctrl = FindContentViewControl("fullContent1" + i, itemContainer);
                if (ctrl is HyperLink && Membership.GetUser(UserManager.GetCurrentUser()) != null)
                {
                    ((HyperLink)ctrl).NavigateUrl = contentItem.UrlWithExtension;
                }
                else
                {
                    System.Web.HttpContext.Current.Response.Redirect("~/Login.aspx");
                }
            }
        }

    All the best
    Johnny
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Sep 2010
    Link to this post
    Hello Johnny,

    SetItemMetadata is in Master view as well and in your else statement you make a redirect when the user is not authenticated. You are making redirect to the login form

    System.Web.HttpContext.Current.Response.Redirect

    but you have only to set the NavigateUrl in case the user is not logged in.

    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
  9. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    02 Sep 2010
    Link to this post
    Finally(I think...) in one of the previous answers:
    "As for the ASP.NET Login control, the server looks for an authentication cookie. If it fails to find the authentication cookie, the user is redirected to the configured logon page (Login.aspx), as specified by the LoginUrl attribute of the forms element. The user supplies and submits credentials through this form. Information about the originating page is placed in the query string using RETURNURL as the key.  You can explicitly force setting the QueryString in the url and the Login control will read it automatically." How can I force setting the queryString to read it automatically?
    protected void Login1_LoggedIn(object sender, EventArgs e)
        {
            string redirectUrl = Request.QueryString["ReturnUrl"];
            if (!string.IsNullOrEmpty(redirectUrl))
            {
                redirectUrl = HttpUtility.UrlDecode(redirectUrl);
                this.Response.Redirect(redirectUrl, true);
            }
            else
                Response.Redirect(DestinationPageUrl);
        }
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Sep 2010
    Link to this post
    Hi Johnny,

    You have to add the QueryString with the return page in the Url.

    sample

    String.Concat("ReturnURL=", Context.Server.UrlEncode(Context.Request.RawUrl));

    Best wishes,
    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
  11. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    02 Sep 2010
    Link to this post

    Really sorry for beeing a pain but I still don´t get how all of this is tied together.

    protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
      
            for (int i = 1; i < 6; i++)
            {
                var ctrl = FindContentViewControl("fullContent1" + i, itemContainer);
                if (ctrl is HyperLink && Membership.GetUser(UserManager.GetCurrentUser()) != null)
                {
                    ((HyperLink)ctrl).NavigateUrl = contentItem.UrlWithExtension;
                }
            }
        }

    protected void Login1_LoggedIn(object sender, EventArgs e)
        {
            //You have to add the QueryString with the return page in the Url. 
            //String.Concat("ReturnURL=", Context.Server.UrlEncode(Context.Request.RawUrl));
              
            //string redirectUrl = Request.QueryString["ReturnURL"];
            string redirectUrl = String.Concat("ReturnURL=", Context.Server.UrlEncode(Context.Request.RawUrl));
            //string redirectUrl = String.Concat(Request.QueryString("ReturnURL=", Context.Server.UrlEncode(Context.Request.RawUrl)));
            if (!string.IsNullOrEmpty(redirectUrl))
            {
                redirectUrl = HttpUtility.UrlDecode(redirectUrl);
                this.Response.Redirect(redirectUrl, true);
            }
            else
                Response.Redirect(DestinationPageUrl);
        }
  12. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    07 Sep 2010
    Link to this post
    Does anyone have any experience in this and is willing to share?

    //Johnny
  13. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    13 Sep 2010
    Link to this post
    Hello team,

    The forums dont seem to have the answer for this. Is it better to open up a more formal support ticket?

    Thanks for any help.
    //Johnny
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Sep 2010
    Link to this post
    Hello Johnny,

    1. Inside SetItemMetadata you do not pass "ReturnURL" key in the QueryString

    2. If the user is not authenticated ReturnUrl is automatically and internally build from ASP.NET Login control - var returnUrl =FormsAuthentication.GetReturnUrl(false);

    All the best,
    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
  15. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    15 Sep 2010
    Link to this post
    Hello Ivan,

    Could you give me a code example because I don't whats up or down any more. Sorry but I´m totally confused.
    I would really appreciate it!

    /Johnny
Register for webinar
15 posts, 0 answered