Some characteristics of personalization and membership in ASP.net Whidbey

Source: Internet
Author: User
Tags anonymous config contains new features connectionstrings
asp.net in asp.net Whidbey, a basic goal is to reduce development time and code volume 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 the personalized (personalization) and member roles (membership) to focus on in this article, To save you time.

Along with the two new features of personal and member roles, the first step is to configure the provider (provider) that you use to store personalized (personalization) and member role (membership) data. Although you can create an access or SQL Server database yourself by manually adding the necessary configuration elements, an easier way is to use the ASP.net Web Site administration tool, as shown in Figure I.


Figure I

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



To create a. mdb file in access to store personalization data, you need to open the ASP.net Web Site administration tool. In a folder called data, a Aspnetdb.mdb file is automatically created.


Figure II

To configure the membership provider, you need to use the Security tab of the ASP.net Web Site administration tool. The easiest way to do this is to choose to use the wizard, as shown in Figure three.


Figure Three

At the moment, the membership database is created and the necessary configuration elements are added to the Web.config file. All you need to do is to add all the users to the database, set the restricted page, and create a login page.

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

In addition to embedded access and SQL Server providers, you can create your own custom providers and then use these providers to configure your application. In other words, if you have a previous database, you can still use the membership service.



The above are all theoretical, and then let's take a look at the examples. I'll show you how to use Access provider to configure Personalization and membership, add a user to the membership database, add personalization properties, and use these properties on a page , which are anonymous users and logged-in users respectively.

First you create a Web site, and then click the Web Site Administration Tool button under the Solution Explorer window. (See figure II)

Next, click the Security tab, select the Security Setup Wizard radio button, and click Next. The first step is a very simple message, so if you read it, you can choose Next. The second step is to select from the Internet and then click Next. "From the Internet" uses asp.net forms validation to configure the application, and "from a local area network" uses Windows authentication to configure the application. Step three, click Next to use the Web Site Administration tool aspnetdb.mdb files that have been created automatically. Then click Next to skip step fourth. In step fifth, there is at least one user to be added for the purpose of testing. The sixth step is to create an access rule. Finally, press Finish to exit the wizard. The database has been established, the Web.config file has been created automatically, joined the Web site, contains a variety of elements, the file is as follows:

<?xml version= "1.0" encoding= "Utf-8"?>

<configuration>

<connectionStrings>

<add name= "webAdminConnection631974613823397072"

connectionstring=

"C:\inetpub\wwwroot\aspnetPRO_PM\DATA\AspNetDB.mdb"

/>

</connectionStrings>

<system.web>

<membership defaultprovider= "AspNetDB" >

<providers>

<add name= "AspNetDB"

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"

Requiresquestionandanswer= "true"

passwordformat= "Encrypted"/>

</providers>

</membership>

<rolemanager defaultprovider= "AspNetDB" >

<providers>

<add name= "AspNetDB"

Type= "System.Web.Security.AccessRoleProvider,

System.Web, version=1.1.3300.0, Culture=neutral,

PUBLICKEYTOKEN=B03F5F7F11D50A3A "

Connectionstringname=

"webAdminConnection631974613823397072"

Applicationname= "/aspnetpro_pm"/>

</providers>

</roleManager>

<authentication mode= "Forms"/>

</system.web>

</configuration>

It is necessary to allow anonymous users to access your site,<anonymousidentification> elements. The Personalization section contains two properties, the first property, theme, does not specify a type, so it can be treated as a string. The second property, Favoritecolors, specifies the StringCollection class as its type. In this property, if you want to store data for an incompatible StringCollection class, an exception is thrown.

<anonymousidentification enabled= "true"/>

<personalization>

<profile>

<property name= "Theme" allowanonymous= "true"/>

<property name= "Favoritecolors"

Type=

"System.Collections.Specialized.StringCollection"

Allowanonymous= "true"

serializeas= "Xml"/>

</profile>

</personalization>



Now that we understand the configuration personalization and define a provider, it's time to study how to define the value set that makes up the user profile. You need to add a <property> entry for each profile value that you want to store. In fact, you can store any kind of object, a simple type, a string, a Boolean type, or a complex one, such as collections, or even a custom type.

<profile>

<property name= "messagesperpage" type= "int"/>

</profile>

Personalization Systems support more complex types, such as collections. In fact, you can store any serialized object. There is no big difference between defining a complex attribute and defining a simple attribute. The following code contains the definition of a simple and complex attribute.

<personalization enabled= "true" defaultprovider= "Access" >

<providers>

<add name= "Access" type= ... "Connectionname=" ... "/>

<add name= "SQL" type= "... "Connectionname=" ... "/>

</providers>

<profile>

<property

Name= "EmailAddresses"

Type= "System.Collection.Specialized.StringCollection"

Serializeas= "XML"

Allowanonymous= "false"

provider= "SQL"/>

<property name= "messagesperpage" type= "int" defaultvalue= "a"/>

</profile>

</personalization>

Once you have defined the profile of the user, you can begin coding. The page class includes a profile property and is also a httppersonalizationbase subclass. It has the following list of members:


Figure Four



In the membership feature, ASP.net Whidbey provides a number of security controls, the following is a list:

Control
Function

Login
All login features are customized for the site, no code required

LoginView
You can choose from several different templates

PasswordRecovery
Forgotten password control, verifying user identity with select question and answer

LoginStatus
Displays the status of the user's login

LoginName
can display the logged-in user to the page


Let's take the PasswordRecovery control as an example: Add a PasswordRecovery control to the page, and the HTML code is as follows:

<form runat= "Server" >

<asp:passwordrecovery id= "Passwordrecovery1" runat= "Server" font-

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

Borderwidth= "1px" borderstyle= "Solid" backcolor= "#FFFFCC"

Visible=true>

<titletextstyle font-bold= "True" forecolor= "#FFFFFF"

Backcolor= "#333399" >

</titletextstyle>

</asp:passwordrecovery>

</form

In order to implement this function, we need to manually add the following code to the Web.config to specify the SMTP server so that it can send email to the user.

<smtpmail

Servername= "localhost" >

</smtpMail>


Figure Five



We can see that, the next generation of ASP.net Whidbey, control has done very complete, greatly facilitate the programmer's development efficiency, need to write less and more code, let us look at it!


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.