ASP.NET - Personalized Configuration

Build membership

1, Create a new ASPNETDB database: output Aspnet_regsql at the vs2010 command prompt

2. Under the 3.5 version of the new ASP.NET website, modify the configuration file and add a string

3: Set the <profile> configuration section, and often set the three parts

  • <profile> own properties    
  • Subsection <properties> Properties Settings
  • subsection <providers> attribute settings

Providers Property Description
 name specifies the name of the provider instance
  type specifies the type that implements the ProfileProvider abstract base class
connectionStringName The name of the connection string, within the <connectionStrings> configuration section
applicationName specifies the name of the application in the data source that stores the profile data, which can solve the problem of multiple applications using the profile
commandTimeout specifies the timeout in seconds for commands issued to the membership data source
description specifies a description of the profile provider instance
(pictured)

Note: allowAnonymous is used in conjunction with anonymous personalization settings. You can now use it without writing a string collection. You can use it later or ignore it.

ASP.NET configures users to log in on the website management tool page

small example

1: Login.aspx interface

Drag Login directly in the login control column


2: Welcome.aspx interface


3:Addprofile.aspx

Add event for save settings

protected void Button1_Click(object sender, EventArgs e)
    {
        if (!Profile.IsAnonymous)
        {
            Profile.usename = TextBox1.Text;
            Profile.userpwd = TextBox2.Text;
            Profile.birthday = Calendar1.SelectedDate;
            Response.Redirect("Default.aspx");

        }
        else
        {
            Profile.usename = TextBox1.Text;
            Profile.userpwd = TextBox2.Text;
            Response.Redirect("Default.aspx");
 
        }

    }   

4: Default.aspx page is used to display content

protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("昵称:" + Profile.usename + "<br/>密码:" + Profile.userpwd + "<br/>生日:"+Profile.birthday.ToLongDateString());

    }

5: Anonymous Personalization

To enable anonymous personalization, you need to enable the configuration section anonymousIdentification and set the attribute enable to true.

The allowAnonymous attribute and <anonymousIdentification enabled="true"/> must be added together


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324483426&siteId=291194637