Add, delete, modify, and query personalized configuration files

Source: Internet
Author: User

The previous blog post introduced the profile provider and profile dynamic class,

And some basic content about profile. In this blog,

It also introduces the basic content of profile, that is, adding, deleting, modifying, and querying the profile of a single user,

In addition, deletion, modification, and query, the addition and modification are actually the same thing, but they are a coverage problem between values,

In fact, there is no such change,

The change is only to replace the old value of the corresponding attribute with the new value of the profile attribute,

In fact, there are many ways to delete it, but they are all done through profilemanager,

It can be deleted based on the latest activity time or username,

However, there are several methods to query them,

You can use the dynamically generated class profilecommon to find the profile attribute values of a single user,

You can also use the profilemanager class to complete more powerful search functions,

However, this demo only describes how to search for a single user,

Therefore, dynamic profilecommon is used to complete the process,

However, profilemanager is more powerful,

In this case, list it.MsdnMediumProfilemanagerLet's take a look.

Method

Deleteinactiveprofiles
Delete the user configuration file data that appears before the specified date and time of the last activity.
Deleteprofile
Delete the configuration file of the specified user name from the data source.
Deleteprofiles
Overloaded. Delete the properties and information of a series of configuration files from the data source.
Findinactiveprofilesbyusername
Overloaded. Retrieve the configuration file information of the configuration file. In these configuration files,

The date of the last activity is the same as or before the specified date and time,

The User Name of the configuration file matches the specified name.
Findprofilesbyusername
Overloaded. Retrieve the configuration file information of the configuration file that matches the specified name.
Getallinactiveprofiles
Overloaded. Retrieve the user configuration file data of the configuration file. In these configuration files,

The date of the last activity is the same as or earlier than the specified date and time.
Getallprofiles
Overloaded. Retrieve the user profile data of the configuration file from the data source.
Getnumberofinactiveprofiles
Obtain the number of configuration files that are the same as the specified date or earlier than the last activity date.
Getnumberofprofiles
Obtain the number of configuration files in the data source.

The description here is very clear, so I will not introduce it here. If you don't know it, you can check msdn yourself.

In this demo, the deletion operation is also performed on a single user,

In the demo, the user is deleted using profilemanager. deleteprofile (string username)

The search method uses profilecommon. [attribute name] to directly access the attribute,

For Addition and modification, the profile class is used, and then its profile. Sava () method can be called,

Let's take a look at the demo (first look at adding and modifying)

<% @ Page Language = "C #" %>

<SCRIPT runat = "server">
Protected void Btnsava_click (Object sender, eventargs E)
{
// Set or modify the values of a profile
Profile. Address = txtaddress. text;
Profile. constellation = txtconstellate. text;
If (rdbtnhome. Checked)
{
Profile. Phone. Home phone = txtphone. text;
}
Else
{
Profile. Phone. Mobile phone = txtphone. text;
}
// Add or modify a profile
Profile. Save ();
Lblmsg. Text = "added or modified successfully !!! ";
}

Protected void page_load (Object sender, eventargs E)
{
// You must log on first to set the profile (Anonymous is not considered for the moment)
If (User. Identity. isauthenticated = false)
{
Formsauthentication. redirecttologinpage ();
}
Lblusername. Text = user. Identity. Name;
}
</SCRIPT>

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Style type = "text/CSS">
. Style1
{
Width: 43%;
Height: 241px;
Border: 1px solid # 8000ff;
Font-size: small;
}
. Style2
{
Height: 42px;
}
</Style>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div style = "font-family:; font-size: Small">
<Table class = "style1">
<Tr>
<TD>
User name </TD>
<TD>
<Asp: Label Id =" Lblusername "Runat =" server ">
</ASP: Label>
</TD>
</Tr>
<Tr>
<TD>
Address </TD>
<TD>
<Asp: Textbox Id =" Txtaddress "Runat =" server ">
</ASP: textbox>
</TD>
</Tr>
<Tr>
<TD>
<Asp: Radiobutton Id =" Rdbtnhome "Runat =" server"
Groupname = "phone"
TEXT = "home phone" Checked = "true"/>
</TD>
<TD rowspan = "2">
<Asp: Textbox Id =" Txtphone "Runat =" server ">
</ASP: textbox>
</TD>
</Tr>
<Tr>
<TD>
<Asp: Radiobutton Id =" Rdbtnmobile "Runat =" server"
Groupname = "phone"
TEXT = "Mobile Phone"/>
</TD>
</Tr>
<Tr>
<TD>
Constellation </TD>
<TD>
<Asp: Textbox Id =" Txtconstellate "Runat =" server ">
</ASP: textbox>
</TD>
</Tr>
<Tr>
<TD colspan = "2" style = "text-align: Center">
<Asp: Label Id =" Lblmsg "Runat =" server "> </ASP: Label>
</TD>
</Tr>
<Tr>
<TD colspan = "2" style = "text-align: center;
Font-size: small; "class =" style2 ">
<Asp: Button Id =" Btnsava "Runat =" server"
TEXT = "add and modify profile"
Onclick = "btnsava_click"/>
</TD>
</Tr>
</Table>
</Div>
</Form>
</Body>
</Html>

Then let's take a look at the effect of addition and modification.

Log On With chenjing

In this way, this data exists in the aspnet_profile table of the database,

Under the query function, you can see

Now let's take a look at the query and deletion.

<% @ Page Language = "C #" %>

<SCRIPT runat = "server">
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
// Bind all qualified membership members to the dropdownlist
Ddlusername. Items. Clear ();
// Obtain all members
Membershipusercollection usercollection =
Membership. getallusers ();
// Traverse this member set
Foreach (membershipuser user in usercollection)
{
// Add username to dropdownlist
Ddlusername. Items. Add (
New listitem (user. username, user. username ));
}
}
}

Protected void btndelete_click (Object sender, eventargs E)
{
// Delete the configuration file of the user with the specified Username
Profilemanager. deleteprofile (ddlusername. selectedvalue );
Lbldeletemsg. Text = "deleted profile !!! ";
}

Protected void btnquery_click (Object sender, eventargs E)
{
// The first step is to instantiate a dynamically generated class profilecommon
// This class represents a user's profile
Profilecommon usercommon =
Profile. getprofile (ddlusername. selectedvalue );

Lbluser. Text = Usercommon. Username;
Lbladdress. Text = Usercommon. address;
Lblconstellate. Text = Usercommon. constellation;
Lblphone. Text = Usercommon. Phone. Home Phone +
"" + Usercommon. Telephone. Mobile phone;
}
</SCRIPT>

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Style type = "text/CSS">
. Style1
{
Width: 38%;
Border: 1px solid # 8000ff;
Height: 179px;
}
. Style2
{
Width: 259px;
}
. Style3
{
Width: 117px;
}
</Style>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div style = "font-family:; font-size: Small">
Select the user name to delete the profile <br/>
<Br/>
<Asp: Dropdownlist Id =" Ddlusername "
Runat = "server" width = "200px">
</ASP: dropdownlist>
<Br/>
<Br/>
<Asp: Label Id =" Lbldeletemsg "Runat =" server ">
</ASP: Label>
<Br/>
<Br/>
<Asp: Button Id =" Btndelete "Runat =" server"
Onclick = "btndelete_click" TEXT = "Confirm deletion"/>
& Nbsp;
<Asp: Button Id =" Btnquery "Runat =" server"
Onclick = "btnquery_click"
TEXT = "Search for profile"/>
<Br/>
<Br/>
<Table class = "style1">
<Tr>
<TD class = "style3">
User name </TD>
<TD class = "style2">
<Asp: Label Id =" Lbluser "Runat =" server ">
</ASP: Label>
</TD>
</Tr>
<Tr>
<TD class = "style3">
Address </TD>
<TD class = "style2">
<Asp: Label Id =" Lbladdress "Runat =" server ">
</ASP: Label>
</TD>
</Tr>
<Tr>
<TD class = "style3">
Phone number </TD>
<TD class = "style2">
<Asp: Label Id =" Lblphone "Runat =" server ">
</ASP: Label>
</TD>
</Tr>
<Tr>
<TD class = "style3">
Constellation </TD>
<TD class = "style2">
<Asp: Label Id =" Lblconstellate "Runat =" server ">
</ASP: Label>
</TD>
</Tr>
</Table>
<Br/>
</Div>
</Form>
</Body>
</Html>

The above section completes the deletion and query of profiles for individuals.

Better results

Search for Xiaozhen first

Then look for chenjing.

Try again to find a profile that has not been defined for it (you can see that there is nothing)

The deletion function is demonstrated.

Delete chenjing first (you can see that the deleted profile attribute values are empty)

Try to delete a profile that has not been set (the profile will be deleted as null)

Through the above demos, we have completed the addition, deletion, modification, and query of personal profiles,

Of course, there are thousands of website users. If they are deleted for individuals,

There will be no dead-end users. If there will be too many anonymous users in the future,

After a period of time, we should delete the profile of an anonymous user who has not been active for a long time,

In this way, the database can be effectively managed,

As mentioned later, I think you can check msdn to solve this problem !!!

2010-2-09

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.