More in this section

Forums / Developing with Sitefinity / Logging access attempts to admin UI

Logging access attempts to admin UI

6 posts, 1 answered
  1. Jon
    Jon avatar
    22 posts
    Registered:
    11 Mar 2010
    24 Mar 2010
    Link to this post
    I'd like to log when users attempt and successfully log into the Sitefinity UI.  I read a post about using Google Analytics, but I'd prefer to leverage Sitefinity logging, if possible, and keep the logging server side.

    Any recommendations?

    Thanks,

    -Jon
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    24 Mar 2010
    Link to this post
    Hello Jon,

    The easiest way to do this is to make the LoginControl write some logs in the LoggedIn event. You can edit the ~/Sitefinity/UserControls/Login/LoginControl.ascx.cs:
    void Page_Load(object sender, EventArgs e)
    {
        this.Login1.LoggedIn += new EventHandler(Login1_LoggedIn);
    }
     
    void Login1_LoggedIn(object sender, EventArgs e)
    {
        UserManager userManager = new UserManager(Login1.MembershipProvider);
        MembershipUser user = userManager.GetUser(Login1.UserName);
        //write some log information
        string userName = user.UserName;
        Guid userID = (Guid)user.ProviderUserKey;
    }


    Sincerely yours,
    Radoslav Georgiev
    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. Jon
    Jon avatar
    22 posts
    Registered:
    11 Mar 2010
    24 Mar 2010
    Link to this post

      Clearly this also needs to be added:

    using Telerik.Security;
    using System.Web.Security;

    to

    ~/Sitefinity/UserControls/Login/LoginControl.ascx.cs:
  4. Jon
    Jon avatar
    22 posts
    Registered:
    11 Mar 2010
    24 Mar 2010
    Link to this post
    I don't see how this writes to the sitefinity log file.

  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    24 Mar 2010
    Link to this post
    Hello Jon,

    You can add your own logic for writing to a log file. I would not recommend writing to sitefinity.log file because it will add too much entries in between more important events being logged.

    All the best,
    Radoslav Georgiev
    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
  6. Jon
    Jon avatar
    22 posts
    Registered:
    11 Mar 2010
    24 Mar 2010
    Link to this post
    So that someone else looking for adding logging might be able to benefit ...

    The part of the question not answered could be handled like this:


    /// Handles error by accepting the error message
        /// Displays the page on which the error occured
        public static void WriteError(string errorMessage)
        {
            try
            {
                string path = "~/Error/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
                if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
                {
                    File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close();
                }
                using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path)))
                {
                    w.WriteLine("\r\nLog Entry : ");
                    w.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
                    string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
                                  ". Error Message:" + errorMessage;
                    w.WriteLine(err);
                    w.WriteLine("__________________________");
                    w.Flush();
                    w.Close();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message);
            }
      
        }




Register for webinar
6 posts, 1 answered