Membership kontrolleri ASP.net 2.0 la gelen yeniliklerden birisi. Kullanıcı ile ilgili bir çok modül hazır olarak bulunmakta. Varsayılan alanlar haricinde, kullandığımız özel alanlar aspnet_Profile tablosunda tek bir sütunda tutulur ve aspnet_User tablosuyla UserId alanından ilişkilendirilmiştir. Bir asp.net web sayfasında kullanacaksak problem yok, database den direk bu kayıtları görmemiz gerekirse işimiz pek de kolay değil. Bu tarz bir ihtiyaçta aşağıdaki fonksiyon kullanılabilir.
aspnet_Profile.PropertyNames : Profil alanların isim ve pozisyonlarının tutulduğu sütun
aspnet_Profile.PropertyValuesString : Profil değerlerinin tutulduğu sütun
CREATE FUNCTION [dbo].[GetProfileProperty](
@profileName varchar(50),
@PropertyNames varchar(8000),
@PropertyValuesString varchar(8000)
)
RETURNS varchar(500)
AS
BEGIN
DECLARE @MyOutput varchar(1000)
SET @MyOutput=substring (
@PropertyValuesString,
convert(int,(substring(@PropertyNames,charindex(@ProfileName,@PropertyNames,1) + len(@ProfileName) + 3,
(charindex(':',@PropertyNames,charindex(@ProfileName,@PropertyNames,1) + len(@ProfileName) + 3)- charindex(@ProfileName,@PropertyNames,1) - len(@ProfileName) - 3))
)) + 1,
convert(int,(substring(@PropertyNames,charindex(':',@PropertyNames,charindex(@ProfileName,@PropertyNames,1) + len(@ProfileName) + 4) + 1,
((charindex(':',@PropertyNames,charindex(':',@PropertyNames,charindex(@ProfileName,@PropertyNames,1) + len(@ProfileName) + 4) + 1))-(charindex(':',@PropertyNames,charindex(@ProfileName,@PropertyNames,1) + len(@ProfileName) + 4) + 1)
))))
)
RETURN @MyOutput
END
Bu fonksiyonu kullanarak,
SELECT dbo.GetProfileProperty('Firma',PropertyNames,PropertyValuesString)
FROM dbo.aspnet_Profile
cümlesiyle tüm kullanıcıların firma bilgisini alabiliriz.
0 yorum:
Yorum Gönder