More in this section

Forums / Developing with Sitefinity / Get currently-logged-in UserInfo

Get currently-logged-in UserInfo

15 posts, 0 answered
  1. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    18 Oct 2009
    Link to this post
    Hi!
    I can't find information about how to get info of currently-logged-in user with Sitefinity API. I want to get UserName and UserID (Guid) of currently-logged-in user. How can I do this? 
    Thank you.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    18 Oct 2009
    Link to this post
    Hello Paul,

    Please take a look at the sample shown below:

    string UserName = UserManager.GetCurrentUserName();
    MembershipUser membershipUser = Membership.GetUser();
    string userID = membershipUser.ProviderUserKey.ToString();
    Literal1.Text = "The currently logged user is:" + UserName + " " + "and its ID is:" + userID;

    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. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    19 Oct 2009
    Link to this post
    Hi Ivan!
    Thank you for the snippet! It really helps.
    Maybe you can suggest me how to catch blog ID for each item in BlogsView control or from PostsView control?
    Thank you.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Oct 2009
    Link to this post
    Hello Paul,

    You can create a custom class that inherits BlogPosts, then override SetItemMetadata method. There you can access to the contentitem object from where you can get the ParentID property. The Guid that you will have is the ID of the blog under this content item was created.

    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.
  5. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    20 Oct 2009
    Link to this post
    Hi Ivan!
    Thanks for your reply.
    I don't understand how I can get blog ID by overriding SetItemMetaData. I found this tutorial in developer manual: http://www.sitefinity.com/help/developer-manual/extending-built-in-controls-content-view-control.html . Can you expalin more clearly what do you mean?
    Also I understand that I need to get post ID and send it to my method. Let me explain: in blogposts each post have two buttons - increase raiting and decrease raiting. I want to have post ID of each post. How can I do this?
    Thank you.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Oct 2009
    Link to this post
    Hello Paul,

    Bellow is a sample code that illustrates how to get the postID and parentID of each post.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Blogs.WebControls;
    using System.Web.UI.WebControls;
     
    /// <summary>
    /// Summary description for BlogPostsCustomControl
    /// </summary>
    public class BlogPostsCustomControl : BlogPosts
    {
        public BlogPostsCustomControl()
        {
        }
         public override string  SingleItemTemplatePath
         {
         get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
            }
         
         }
     
        public override string  ItemListTemplatePath
        {
            get
            {
             return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageMaster.ascx";
            }
        }
     
        
        protected override void  SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
            Literal literal = (Literal)itemContainer.FindControl("postID");
            if (literal != null)
            {
                literal.Text = "ParentID is:" + contentItem.ParentID.ToString() + " " + "postID is:" + contentItem.ID.ToString();
            }
        }
            
    }


    Kind 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.
  7. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    20 Oct 2009
    Link to this post
    Hi Ivan!
    Thank you for the snippet.
    But I need to get post ID not in the admin part. I want to add every user of my site rate each post. How do I need to change your snippet for this task?
    Thank you. 
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Oct 2009
    Link to this post
    Hi Paul,

    This is a class that derives from BlogPosts which is a public control. I am not sure whether you have tried the example or implement it, but it will be good if you do it.

    As for the rating you need to add two buttons. I thought that you have already done this -"in blogposts each post have two buttons " In the custom class I sent you, you need to find the controls as I did for my Literal control and then subscribe for button click event of each button where you need to add your posts rating logic. From the next SP of Sitefinity you will be able to use Telerik Rating Control.

    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.
  9. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    20 Oct 2009
    Link to this post
    I will try this example later.Thank you for the answer.
    Great news about Rating control. When will you release next SP? (if it is not a secret :) )
    And what do you think about comments? How can I implement rating for the comments? I have some ideas how to do it but I have the same troubles with getting comment ID.
    Thank you.

  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Oct 2009
    Link to this post
    Hi Paul,

    You can get the comments and comment ID for a specific post as shown below:

    IList commentList = manager.GetComments(contentItem.ID);
    foreach (IComment comment in commentList)
    {
        string commentID = comment.ID.ToString();
    }


    Greetings,
    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.
  11. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    20 Oct 2009
    Link to this post
    Hi Ivan!
    I have troubles with postID. Please tell me what I'm doing wrong. In my templates for blogpost I add literal postID.After that I add a new class library project to solution. Add new class BlogPostCustomControl. In this class I paste code bellow. After build succeeding I upload new Dll but I have no any effect.
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Blogs.WebControls; 
    using System.Web.UI.WebControls; 
      
    /// <summary> 
    /// Summary description for BlogPostsCustomControl 
    /// </summary> 
    public class BlogPostsCustomControl : BlogPosts 
        public BlogPostsCustomControl() 
        { 
        } 
         public override string  SingleItemTemplatePath 
         { 
         get 
            { 
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/ContentViewSingleItem.ascx"
            } 
          
         } 
      
        public override string  ItemListTemplatePath 
        { 
            get 
            { 
             return "~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascx"
            } 
        } 
      
         
        protected override void  SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem) 
        { 
            base.SetItemMetadata(itemContainer, contentItem); 
            Literal literal = (Literal)itemContainer.FindControl("postID"); 
            if (literal != null
            { 
                literal.Text = "ParentID is:" + contentItem.ParentID.ToString() + " " + "postID is:" + contentItem.ID.ToString(); 
            } 
        } 
              
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Oct 2009
    Link to this post
    Hello Paul,

    First use ListPageMaster and ListPageDetail templates. As for the problem you have - It is not necessary to compile the code, you can add it to App_Code folder. Anyhow, have you registered the assembly in your web.config file? What is the result if you attach a debugger?

    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.
  13. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    21 Oct 2009
    Link to this post
    Hi Ivan!
    First of all I am using External Templates. I tried your code with ListPageMaster and ListPageDetail templates and it also didn't work. 
    >Anyhow, have you registered the assembly in your web.config file? What is the result if you attach a debugger?
    I have not registered the assembly in my web.config. 
    I know that I am doing something wrong but I don't understand what =(
    Can you describe all steps of development this function?
    Thank you.
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Oct 2009
    Link to this post
    Hello Paul,

    I see that you are using external templates, but they are not the right one. The templates you use are added for backward compatibility for versions before 3.5. If you took a look at my code it uses external templates.

    I have not registered the assembly in my web.config.

    Then you cannot see the control in the front end. This is a custom control that inherits from EventsView. It is EvensView extension. As you have mentioned you want to modify the public control.
    You need to register the namespace of the control and then use it.

    example


    <toolboxControls>
    ....
       ....
     
    <add name="EventsViewCustomControl" section="Custom" type="EventsViewCustomControl, MyCustomDll"/>
     
    // or
     
    <add name="EventsViewCustomControl" section="Custom" type="EventsViewCustomControl, App_Code"/>


    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.
  15. Paul
    Paul avatar
    176 posts
    Registered:
    18 Nov 2008
    21 Oct 2009
    Link to this post
    Hi Ivan!
    In this cases I am feeling myself so stupid =)
    You really help me man. Now I understand how it works and where I was wrong. Everything works fine now!
    Thank you.
Register for webinar
15 posts, 0 answered