Data Mining

Download Free Data Mining Source Code In C/C++, C#, Visual Basic, Visual Basic.NET, Java,
and other programming languages
Welcome to Data Mining Sign in | Join | Help
in Search

Data Mining Source Code Newsletter

Business Analyst Training
Live, Online, Video Courses
Instructor-Led + Hands-On
BusinessAnalystBootCamp.Com

SQL + Database Training
Live, Online, Video Classes
Instructor-Led + Hands-On
SQLBootCamp.Com

Software Developer Training
Live, Online, Video Courses
Instructor-Led + Hands-On
SoftwareDevelperBootCamp.Com

IT CAREER COACH
Hands-On Experience Coaching
IT Skills Training
IT-Career-Coach.NET

IT Professional Newsletter
"Free" IT Career Success Tips
How To Accelerate Your Career
IT Career Newsletter

Ask IT Career Questions
"ASK" A Burning IT Career
Question Or Get Answers
Ask A Burning IT Question Now!

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed

Advanced Personalization Services in ASP.NET 2.0 Part2

Last post 02-18-2005, 17:23 by khaledhussein. 0 replies.
Sort Posts: Previous Next
  •  02-18-2005, 17:23 4135

    Advanced Personalization Services in ASP.NET 2.0 Part2

    Advanced Personalization Services in ASP.NET 2.0 Part2

     

    Khaled Hussein.

    E-Business Solution Developer

     

    February 2005

     

    Applies to:

    Microsoft ASP.NET 2.0

    Microsoft Access 2003

    Microsoft Visual Studio 2005 Beta 1 Codename "Whidbey"

     

    Summery: learn how to implement the second aspect of personalization features in your web applications using Profile object provided by ASP.NET 2.0.

     

    Introduction

     

    This is part 2 in the Advanced Personalization Services series. In part 1 we discussed the new infrastructure feature of ASP.NET 2.0. Membership is used to store user credentials and it offers a way to manage them by validating, editing and deleting them.

     

    One of the ideas that always pops up in part 1 reader's minds is that now we know how to store the username and password so what if I want to store more information about the user like his first name, last name, phone, address, … etc. but membership wasn't designed for storing such information.

     

    Personalization is the part of ASP.NET 2.0 which is responsible for storing any additional user information. We will examine personalization in ASP.NET 2.0 through part 2 using Profile object, and see we can implement personalized pages using ASP.NET 2.0.

     

    Profiles

     

    User profile is simple a profile that contains all the users information that is needed to be stored about this user. Whenever you visit any web site that offers some kind of a personalized service you will find them asking you to login if you are a registered user otherwise to sign up. Do you have any idea why they doing this? No don't worry, not to SPAM your e-mail J, they want to keep a profile about you store all the information they can get about you, using this way they can benefit by customizing their services just to fit your needs which is raising their success percentage in going into new business ideas.

     

    Now we know what a profile is, but what is a profile in ASP.NET 2.0. Well it is exactly the same, but in order to imagine how things work. We need to remember some things from ASP.NET 1.x.

     

    In ASP.NET 1.x, if you wanted to store specific information about the user during his visit you store it in Session object, which means that a Session in ASP.NET 1.x was some sort of a replacement to Profiles if it is not stored in a database. Session was a collection of objects, which is different in ASP.NET 2.0 so we can say Profile object is a replacement to the use of Session collection in ASP.NET 1.x.

     

    The information that is stored in Session collection are lost after the specific session is ended. Profile object is unlike Session collection, stored and maintained through user visits and is managed through out the user sessions.

     

    Profile uses a storage provider model that we explained in part1 to store the data , by default the user's data that are in his profile is stored in Microsoft access data base. But also we have the choice to change the provider and store these data to Microsoft SQL Server, ORACLE data base, or even a customized provider. 

     

    Profile is configured using XML Schema stored in web.config. Once you configured the schema and you saved web.config file, the information is available to the IDE, and the runtime.

     

    What does this mean? YES, it means that now Profile object offers typed properties to store the data for our visitors. ASP.NET 2.0 Personalization system stores any type of data ranging from simple data types (string, int …) to much more complex user data types which of course gives you a great flexibility in your application design.

     

    Profile object is working seamlessly with Membership feature but of course it can work independently.

     

     

     

    Creating Profiles

     

    Profiles as we mentioned before is configured using set of XML tags which are stored in web.config

    Let's see a sample of configuring a web.config to support Profile.

     

    <configuration>

         <system.web>

              <personalization>

                    <profile>

                            <property name="FirstName" type="System.String"/>

                            <property name="LastName" type="System.String"/>

                    </Profile>

                </personalization>        

           </system.web>

    </configuration>

     

    This personalization configuration by default is configured to use AspNetAccessProvider, but we can easily change this provider by choosing any other provider from the ones found in the <personlization/> element.

     

    The properties that we defined are by default mapped to typed properties in Profile object. As you can notice here we created two properties.

     

    ·          FirstName is a string property that is used to store the first name of the user.

    ·          LastName is a string property that is used to store the last name of the user.

     

    But how can these properties access from code? Let's see the answer to this question.

     

    Profile.FirstName = "Khaled";

    Profile.LastName = "Hussein";

     

    See it is easy! Isn't that cool?

     

    The profile object provides read and write access to the current user's profile properties stored in the web.config file.

     

    One of the questions that are frequently asked in this area that the user can have lots of information that need to be stored in his profile, can't we make some kind of arrangements and grouping for these properties? The answer is yes you can and when you make grouping for properties under logical group is managed as a property that has sub properties and you still can access them through the Profile object. I will show you now how you can make grouping of user properties together under a logical group and how you can access them through code.

     

    <profile>

                <group name="PersonalInformation">

                            <property name="FirstName" type="System.String"/>

                            <property name="LastName" type="System.String"/>

                </group>

                <group name="BusinessInformation">

                            <property name="BusinessPhone" type="System.String"/>

                            <property name="BusinessAddress" type="System.String"/>

                </group>

    </profile>

     

    As you can easily expect that we have just created two logical groups ("PersonalInformation" and "BusinessInformation").

    And each one of these groups contains some properties that belong to this group.

    Now let's see how we can access one of these properties through code.

     

    Profile.PersonalInformation.FirstName = "Khaled";

     

    Profile.BusinessInformation.BusinessPhone = "00123456789";

     

    Setting up the data base for personalization

     

    ASP.NET 2.0 is now shipped with two personalization providers, and they are:

     

    ·          Microsoft Access Provider

    ·          Microsoft SQL Server Provider

     

    As we mentioned before that personalization is configured by default to user Microsoft Access Provider, which is defined in the class called System.Web.Personalization.AccessPersonalizationProvider.

    But we can easily change this using the <personalization> element.

    <personalization defaultProvider="AspNetAccessProvider"/>

     

    Using the SQL Server Personalization Provider

     

    Changing the default Microsoft access provider to Microsoft SQL Server personalization provider is a very easy task to do, actually there are two ways we can do this.

     

    First method is using the Web Site Administration Tool that we already discussed in part1. And you can go to the profile tab and start choosing the provider you want to use whether it is Microsoft Access or Microsoft SQL Server.

     

    Microsoft SQL Server is of course much recommended for real business applications, and Microsoft access is a good choice for small applications or personal ones.

     

    Second method is the ASP.NET SQL Server Setup Wizard: this tool can be used to setup a SQL Server for use in all of the ASP.NET 2.0 features.

     

    Let's have a look at this tool, and learn how we can use it to setup a SQL Server data base to use in ASP.NET 2.0 personalization feature.

     

    ASP.NET SQL Server Setup Wizard

     

    The ASP.NET SQL Server Setup Wizard is used to configure SQL Server to support various features in ASP.NET 2.0 including (Membership, Personalization … etc.).

    This utility is a command line and a Graphical User Interface utility. The tool's name is aspnet_regsql.exe, this tool is usually can be found int \(your windows directory)\Microsoft.Net\Framework\(Framework Version)\.

     

    Let's start with the GUI mode first and then move on to the command line mode. The GUI mode is so simple and it configures the SQL Server to support all the features that are provided by ASP.NET 2.0.

     

    To run the GUI Tool, all you have to do is to browse to asp_regsql.exe and double click on it, or you can run it from the command line without any arguments it will start the wizard and display the welcome screen.

    ASP.NET 2.0 SQL SERVER SETUP WIZARD 2

    Click next to continue with the wizard, you will find two setup options:

    ASP.NET 2.0 SQL SERVER SETUP WIZARD 2;

    ·          Configure SQL Server: This option means that the tool is going to run some SQL scripts that will configure the SQL Server automatically for you. These scripts can be found in the same path as this tool. You will find also there Installing scripts and Uninstalling ones, so if you wanted to uninstall all you have to do is to call these scripts (if you don't want to use the wizard).

    ·          Uninstall SQL Server ASP.NET features: just runs the uninstalling script for you. And it will remove all the structure that was made in SQL to support ASP.Net 2.0 features.

    We will choose the first choice and then click next to continue with the wizard.

    Here is step2: Select the SQL Server and Data Base. In this step all you have to do is type in your SQL Server Address, choose the authentication method whether Windows Authentication or SQL Server Authentication using your SQL Server username and password, and finally you choose your DATABASE that is going to be configured to support ASP.NET 2.0 features.

     

    When you click next you will find a final screen it is just to confirm your selections and when you click finish the installation process will begin. Once it is completed you will get a screen telling you the status of running the scripts with success or failure, and you can then close the wizard.

     

    Conclusion

     

    In this article we learned about profiles, its benefits, and how we can implement them in our applications. Also we learned how change the default configuration of Profile Providers.

    In part 3 we will learn how can create our own customized provider and we will examine some of the new controls that are used to personalize web applications.

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed