Some features in Personalization and Membership in ASP.NET Whidbey

zhaozj2021-02-16  51

In ASP.NET WHIDBEY, a basic goal is to reduce development time and code amount when developing applications. To achieve this, ASP.NET Whidbey provides a range of new features, such as data binding without code, new server-side controls, especially, in this article, Personalization and Personalization and Member role (Membership) to save your time.

With the two new features of personalization and members roles, the first step is to configure the provider you used to store personalization and member role (Membership) data. Although you can create an Access or SQL Server database you can manually add the necessary configuration elements, a simpler method is to use the ASP.NET Web Site Administration Tool, as shown in Figure 1.

Figure one

Note that you must successfully configure an application, you must use an account with administrator privileges to log in.

To create an Access .mdb file to store the Personalization's data, you need to open the ASP.NET Web Site Administration Tool. Under a folder called Data, an aspnetdb.mdb file is automatically created.

Figure II

To configure the MEMBERSHIP's Provider, you need to use the ASP.NET Web Site Administration Tool's Security tab. The easiest way is to select the use wizard, as shown in Figure 3.

Figure three

At this moment, Membership's database is created, and the necessary configuration elements will also be added to the web.config file. What you need to do is just to join all users to the database, set the restricted page, and create a login page.

It is important to note that you can use the same provider for the database created for Personalization and MemberShip, so you can use the same provider.

In addition to embedded Access and SQL Server's Providers, you can create your customized Providers and use these Providers to configure applications. That is, if you have a previous database or you can use the Membership service.

The above is theoretical, then let's take a look at the example. I will display the readers to use Access Provider to configure Personalization and Membership, add one user in the Membership database, add Personalization properties, use these properties in a page, are anonymous users and logged in users.

First create a Web site, then click the Web Site Administration Tool button under the Solution Explorer window. (See Figure 2)

Then, click the Security tab, select the Security Setup Wizard single button, and click Next. The first step is very simple information, so read it, you can choose Next. Step 2, select from the Internet and click Next. "From the Internet" is an application using ASP.NET Forms to configure applications, "From A Local Area Network" uses Windows authentication to configure applications. Step 3, click Next to use the ASPNETDB.MDB file that the Web Site Administration Tool has automatically created. Then, the next NEXT skips the fourth step. In the fifth step, because of the purpose of test, at least one user is to be added. The sixth step is to create access rules. Finally, press Finish to exit the wizard. The database has been established, the web.config file is also automatically created, adding the Web site, including various elements, the files are as follows:

CONNECTIONSTRING =

"C: /inetpub/wwwroot/aspnetpro_pm/data/aspnetdb.mdb"

/>

TYPE = "System.Web.Security.accessmembershipProvider,

System.Web, Version = 1.1.3300.0, Culture = Neutral,

PublickeyToken = B03F5F7F11D50A3A "

ConnectionstringName =

"WebAdminConnection631974613823397072"

ApplicationName = "/ aspnetpro_pm"

EnablepasswordRetrieval = "true"

EnablepasswordReset = "true"

RequiresqusquestInSwer = "true"

PasswordFormat = "encrypted" />

TYPE = "System.Web.Security.accessRoleProvider,

System.Web, Version = 1.1.3300.0, Culture = Neutral,

PublickeyToken = B03F5F7F11D50A3A "

ConnectionstringName =

WebadminConnection631974613823397072 "ApplicationName =" / aspnetpro_pm "/>

If you want to allow anonymous users to access your site, element is required. The Personalization section contains two properties, the first attribute, theme, does not specify a type, so you can treat it as a string. The second attribute, FavoriteColors, specifies the StringCollection class as its type. In this property, you will throw an exception if you want to store data that is not compatible with the StringCollection class.

TYPE =

"System.collections.specialized.stringcollection"

AllowAnonymous = "true"

SerializeAs = "XML" />

Now, we understand the configuration of Personalization and define a provider, now how to define how to form the Value set for the user profile. You need to add a entry for each profile value you want to store. In fact, you can store any kind of object, simple type, string, Boolean type, or complicated, such as Collections, or even custom types.

The Personalization system supports more complex types such as Collectes. In fact, you can store any serialized objects. In fact, a complex attribute and definition is not too much different. The next code contains the definition of simple and complex properties.

Type = "system.collection.specialized.stringcollection"

SerializeAs = "XML"

AllowAnonymous = "false"

Provider = "sql" />

After defining the user's profile, you can start encoding. The Page class includes a profile property and a subclass of HttpPersonalizationBase. It has a list of members:

Figure four

In the Membership feature, ASP.NET Whidbey provides a lot of security controls. Here is a list:

The control function login customizes all login functions for the site, does not require any code loginview to select several different template PasswordRecovery "Forgot Password" control, use the selection problem and answer to verify that the user identity loginstatus Display the status of the user login loginname can Login user is displayed on the page

We will raise the PasswordRecovery control: Add a PasswordRecovery control on the page, the HTML code is as follows:

Names = "Verdana" font-size = "10pt" bordercolor = "# 999999"

BorderWidth = "1px" borderstyle = "solid" backcolor = "# fffcc"

Visible = True>

Backcolor = "# 333399">

In order to implement this feature, we need to manually add the following code to web.config, specify the SMTP server, so that Email can be sent to the user.

ServerName = "localhost">

Figure 5

We can see that the new generation of ASP.NET Whidbey, the control has been made very complete, greatly facilitating the development efficiency of programmers, and the code you need to write is less and less, let us wait and see!

转载请注明原文地址:https://www.9cbs.com/read-23134.html

New Post(0)