I believe many people use profile to store user information, such as company names. However, it is very difficult to list user information in the background. Please try my method.
1. Create a view in the database: view_profile
Select DBO. aspnet_users.applicationid, DBO. aspnet_users.username,
DBO. aspnet_profile.propertynames, DBO. aspnet_profile.propertyvaluesstring,
DBO. aspnet_profile.propertyvaluesbinary
From DBO. aspnet_profile inner join
DBO. aspnet_users on DBO. aspnet_profile.userid = DBO. aspnet_users.userid
2. Create a stored procedure in the database: proc_profile_getprofiles
Create procedure DBO. proc_profile_getprofiles
@ Applicationname nvarchar (256)
As
Begin
Declare @ applicationid uniqueidentifier
Select @ applicationid = NULL
Select @ applicationid = applicationid from DBO. aspnet_applications where lower (@ applicationname) = loweredapplicationname
If (@ applicationid is null)
Return
Select username, propertynames, propertyvaluesstring, propertyvaluesbinary
From DBO. view_profile
Where applicationid = @ applicationid
End
3. create a new class: qwpusercontroller
public class qwpusercontroller
{< br> Public static list getusers ()
{< br> type = httpcontext. current. profile. getType ();
database DB = databasefactory. createdatabase ();
dbcommand = dB. getstoredproccommand ("proc_profile_getprofiles");
dB. addinparameter (dbcommand, "applicationname", dbtype. string, profilemanager. provider. applicationname);
sqldatareader reader1 = (sqldatareader) dB. executereader (dbcommand);
List <profilebase> List = NULL;
If (reader1.hasrows)
List = new list <profilebase> ();
While (reader1.read ())
{
String username = NULL;
String [] textarray1 = NULL;
String text1 = NULL;
Byte [] buffer1 = NULL;
username = reader1.getstring (0);
textarray1 = reader1.getstring (1 ). split (New char [] {':'});
text1 = reader1.getstring (2);
int num1 = (INT) reader1.getbytes (3, (long) 0, null, 0, 0);
buffer1 = new byte [num1];
reader1.getbytes (3, (long) 0, buffer1, 0, num1 );
Profilebase profile = (profilebase) type. getconstructor (New Type [0]). Invoke (new object [0]);
Profile. initialize (username, true );
Parsedatafromdb (textarray1, text1, buffer1, profile. propertyvalues );
List. Add (profile );
}
Return list;
}
Static void parsedatafromdb (string [] names, string values, byte [] Buf, settingspropertyvaluecollection properties)
{
If (names! = NULL) & (values! = NULL) & (BUF! = NULL) & (properties! = NULL )))
{
Try
{
For (INT num1 = 0; num1 <(names. Length/4); num1 ++)
{
String text1 = Names [num1 * 4];
Settingspropertyvalue value1 = properties [text1];
If (value1! = NULL)
{
Int num2 = int. parse (Names [(num1 * 4) + 2], cultureinfo. invariantculture );
Int num3 = int. parse (Names [(num1 * 4) + 3], cultureinfo. invariantculture );
If (num3 =-1 )&&! Value1.property. propertytype. isvaluetype)
{
Value1.propertyvalue = NULL;
Value1.isdirty = false;
Value1.deserialized = true;
}
If (Names [(num1 * 4) + 1] = "S") & (num2> = 0) & (num3> 0) & (values. length> = (num2 + num3 ))))
{
Value1.serializedvalue = values. substring (num2, num3 );
}
If (Names [(num1 * 4) + 1] = "B") & (num2> = 0) & (num3> 0) & (BUF. length> = (num2 + num3 ))))
{
Byte [] buffer1 = new byte [num3];
Buffer. blockcopy (BUF, num2, buffer1, 0, num3 );
Value1.serializedvalue = buffer1;
}
}
}
}
Catch
{
}
}
}
}
4. Use this class to return list <profilebase>
The horse has it.