Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3951704
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:45:45+00:00 2026-05-20T01:45:45+00:00

As far as I can tell, the basic implementation of .Net membership records lastuserlogin

  • 0

As far as I can tell, the basic implementation of .Net membership records lastuserlogin but does not track each login, something I need to do now. I’ve done some research and I’m pretty sure one approach is to create a custom class that extends the current provider with this functionality, and adding an event table to the schema to record each login.

I’ve seen a few articles on this – the closest probably being this one from Scott Mitchell http://dotnetslackers.com/articles/aspnet/Tracking-User-Activity.aspx but it’s from Nov 2008 and I’m curious if anyone can point me towards a better solution for this or confirm this is still the ‘best’ way to tackle this. I would imagine it’s a fairly common requirement. I’m still ramping up on .Net (using c#) so any and all information will be greatly appreciated.

EDIT

Progress but not fully there yet. I added the following code to create a new record in the login activity table:

        if (Request.IsAuthenticated)
        {
            MembershipUser currentUser = Membership.GetUser(false);
            string App1 = Membership.Provider.ApplicationName;
            string username = currentUser.UserName;
            object guid1 = currentUser.ProviderUserKey;
            aspnet_CustomActivity login = new aspnet_CustomActivity
            {
                UserId = (Guid) guid1,
                ActivityID = 1, //login
                DateTime = dt1,
                ApplicationName = App1                   
            };
            db.aspnet_CustomActivities.InsertOnSubmit(login);
            db.SubmitChanges();
        }

So I have a small issue where I noticed ApplicationName is blank and when I tried to change it in web.config it caused an error getting the currentUser.username but I think I can work that out.

What I need to do now to finish is to tie this to the login page and I think I can do that based on the hints below. I’ll post again when complete to round out the answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:45:45+00:00Added an answer on May 20, 2026 at 1:45 am

    We simply created a class that extends the SqlMembershipProvider, overriding the ValidateUser method to perform whatever extra logic we want. (You just need to change the <membership> section of your web.config file to use this new membership provider).

    Edit

    There’s really not much to it. You create a table in your schema that refers to the Guid-based user ID in the standard membership tables. You create a class to manage interaction with this table. You create your membership provider:

    public class MyMembershipProvider : SqlMembershipProvider
    {
        public override bool ValidateUser(string username, string password)
        {
            bool validated = base.ValidateUser(username, password);
            if (validated) 
            {
                MembershipUser user = GetUser(username, false); // built in to SqlMembershipProvider
                new LoginTracker().RegisterLogin((Guid)user.ProviderUserKey);
            }
            return validated;
        }
    }
    

    Then you register this provider in web.config:

    <membership defaultProvider="MyMembershipProvider" userIsOnlineTimeWindow="60">
      <providers>
        <clear/>
        <add name="MyMembershipProvider" ... type="MyAssembly.MyNamespace.MyMembershipProvider, MyAssembly"/>        
      </providers>
    </membership>
    

    Simple!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I can tell i'm doing everything by the book, but the
As far as I can tell, there is no API (official or unofficial) to
As far as I can tell, Scala has definitions for the Enumeration Value class
As far as I can tell, this code is fine, and should display some
As far as I can tell I wouldn't think it would make any difference
I have this trigger which works functionally (as far as I can tell by
That's basically it, as far as I can tell. I can include or require_once
I am an MVC newbie. As far as I can tell: Controller : deals
I'm pretty new to QGraphicsView in Qt. As far as I can tell there
So far I can understand HTML.ActionLink and URL.RouteURL but still trying to absorb where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.