用ASP.Net2.0做項目,發現membership的用戶過段時間就離線了,而我一直在操作啊,郁悶,發現數據表中的最後活動時間字段沒有更 新,最後google了一下,發現這是一個bug,看看存儲過程,的確啊,@UserID變量沒有值啊?!修正了一下,果然工作正常。這個問題到目前都沒 有官方的解決。
相關網址:
http://forums.ASP.Net/thread/1299317.ASPx
http://forums.microsoft.com/MSDN/ShowPost.ASPx?PostID=430091&SiteID=1
以下是修正後的存儲過程:
CREATE PROCEDURE dbo.ASPnet_Membership_GetUserByName
@ApplicationName nvarchar(256),
@UserName nvarchar(256),
@CurrentTimeUtc datetime,
@UpdateLastActivity bit = 0
AS
BEGIN
DECLARE @UserId uniqueidentifIEr
IF (@UpdateLastActivity = 1)
BEGIN
-- Dadi, 11.08.2006
-- Am adaugat eu cda 'select' de mai jos. Fara ea nu se poate executa cda 'update' care actualizeaza LastActivityTime.
--Pb. provine din faptul ca variabila @UserId nu era niciunde initializata
SELECT TOP 1 @userId=u.UserId
FROM dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.ASPnet_Membership m
WHERE LOWER(@ApplicationName) = a.LoweredApplicationName AND
u.ApplicationId = a.ApplicationId AND
LOWER(@UserName) = u.LoweredUserName AND u.UserId = m.UserId
-------------
SELECT TOP 1 m.Email, m.PassWordQuestion, m.Comment, m.IsApproved,
m.CreateDate, m.LastLoginDate, @CurrentTimeUtc, m.LastPassWordChangedDate,
u.UserId, m.IsLockedOut,m.LastLockoutDate
FROM dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.ASPnet_Membership m
WHERE LOWER(@ApplicationName) = a.LoweredApplicationName AND
u.ApplicationId = a.ApplicationId AND
LOWER(@UserName) = u.LoweredUserName AND u.UserId = m.UserId
IF (@@ROWCOUNT = 0) -- Username not found
RETURN -1
UPDATE dbo.ASPnet_Users
SET LastActivityDate = @CurrentTimeUtc
WHERE @UserId = UserId
END
ELSE
BEGIN
SELECT TOP 1 m.Email, m.PassWordQuestion, m.Comment, m.IsApproved,
m.CreateDate, m.LastLoginDate, u.LastActivityDate, m.LastPassWordChangedDate,
u.UserId, m.IsLockedOut,m.LastLockoutDate
FROM dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.ASPnet_Membership m
WHERE LOWER(@ApplicationName) = a.LoweredApplicationName AND
u.ApplicationId = a.ApplicationId AND
LOWER(@UserName) = u.LoweredUserName AND u.UserId = m.UserId
IF (@@ROWCOUNT = 0) -- Username not found
RETURN -1
END
RETURN 0
END
GO