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




Add your Comments

Name:  
Message:


Advertise Here
For more details
Contact Us

Advertisments