Stop Automatic Update of The LastActivity in User Profile

Written by omerkamal on Mar 29, 2007
How to Prevent the Automatic Update of LastActvity in the user Profile using ASP .NET 2.0

Explanation:

When ever a Property of a Profile is accessed it automatically updates the Users Profile's LastActivity. To remove this automatic behaviour you need to trim some part of the ASPNET Datebase Proceedure named "aspnet_Profile_GetProperties".

This Proceedure is excuted when ever Profile GetProperty is accessed. 

Change the aspnet_Profile_GetProperties like Following:

1. Earlier Proceedure:

USE [ASPNETDB.MDF]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[aspnet_Profile_GetProperties]
@ApplicationName nvarchar(256),
@UserName nvarchar(256),
@CurrentTimeUtc datetime
AS
BEGIN
DECLARE @ApplicationId uniqueidentifier
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN

DECLARE @UserId uniqueidentifier
SELECT @UserId = NULL

SELECT @UserId = UserId
FROM dbo.aspnet_Users
WHERE ApplicationId = @ApplicationId AND LoweredUserName = LOWER(@UserName)

IF (@UserId IS NULL)
RETURN
SELECT TOP 1 PropertyNames, PropertyValuesString, PropertyValuesBinary
FROM dbo.aspnet_Profile
WHERE UserId = @UserId

IF (@@ROWCOUNT > 0)
BEGIN
UPDATE dbo.aspnet_Users
SET LastActivityDate=@CurrentTimeUtc
WHERE UserId = @UserId
END


END


You noticed that the Italic Portion of the Proceedure is Updating LastActivity of the Profile. We will Trim This Portion of the Proceedure. Your Proceedure will look the Following.
 
2. Proceedure After Trimimg:

USE [ASPNETDB.MDF]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[aspnet_Profile_GetProperties]
@ApplicationName nvarchar(256),
@UserName nvarchar(256),
@CurrentTimeUtc datetime
AS
BEGIN
DECLARE @ApplicationId uniqueidentifier
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN

DECLARE @UserId uniqueidentifier
SELECT @UserId = NULL

SELECT @UserId = UserId
FROM dbo.aspnet_Users
WHERE ApplicationId = @ApplicationId AND LoweredUserName = LOWER(@UserName)

IF (@UserId IS NULL)
RETURN
SELECT TOP 1 PropertyNames, PropertyValuesString, PropertyValuesBinary
FROM dbo.aspnet_Profile
WHERE UserId = @UserId

END
Visitors/Readers Comments
(for questions please use The Forum)



Aditya
What a solution. thanks!

14/06/2007 01:56:47 UTC

Software_Maker

Yeah! i was searching this solution for long time. Thanks alot!!!!!!!!!!!!!!!!!

14/06/2007 04:05:11 UTC

Thank you!!!
You rock!  Thank you!

01/04/2008 20:51:36 UTC

Indah (a message from germany)
 A Big  Hug and KISS for YOU, thank U very much, u are great !!!!!

09/06/2008 21:17:33 UTC

Hunzonian
If you delete the last activity update procedure, you can never use this function again. There's got to be a better way to do this.

30/06/2008 03:03:46 UTC

Fred

 

I'm not an expert but I would expect
Membership.GetNumberOfUsersOnline to return a different result from the norm

userIsOnlineTimeWindow

29/04/2009 03:51:42 UTC

Joshua
Hello!
Thank you for the tutorials that you have made. It has helped me a lot with my website. I downloaded a programme to help me update the LastActivity in User Profile on http://www.picktorrent.com search engine. Just one question about this one; I only get "Parse error: syntax error, unexpected $end" in the members profile. It says line 35.
Do you think you could help me out? Would be really nice.

10/02/2010 00:57:52 UTC

Kamal
I have faced this problem for a single user, he is not activating the site for long time but this user stays online forever, so i can't able to fix out the problem for the particular user.
Now i came to know the profile properties are called automatically, after remove the piece of query from sp it's working fine!!!!!!!!!

This is really a good solution.

Thanks a lot,

Kamal

09/03/2010 05:13:37 UTC

camellialan

Aw, it was a top quality content. Actually I would like to write like this as well - taking time and real energy to bring about an excellent post... however what can I say... I procrastinate an awful lot and by no means appear to get things completed...

http://simulationassuranceauto.org

07/07/2010 20:39:38 UTC

injury lawyer
Wow! Have not thought of that feature before, but I had some insights into it already though. Thanks for the post anyway!
best regards
http://theaccidentlawyers.org/injury-lawyer/

18/07/2010 21:38:46 UTC

WIKI
The white of an open mouth, a dark silhouette parallel to the water current, or the silver flash of the fish’s side are all signs of a fish.Link Building

22/07/2010 02:29:25 UTC




Add your Comments

Name:  
Message:


Advertise Here
For more details
Contact Us

Advertisments