Showing posts sorted by relevance for query profile. Sort by date Show all posts
Showing posts sorted by relevance for query profile. Sort by date Show all posts

ASP.Net Profile Propety

A website when provides the user to customise the look and feel according to their preferences with their personal touch, it is much liked.
Using profile properties is the best way to provide this functionality along with an important aspect of recognising the user and their preferences and present them with their custom layout.

To implement user profiles we need to follow the following steps
1. Specify where the user profile will be saved. this is done by specifying the Profile Provider.
2. After configuring the profile provider, we have to decide what information we need to save for the user for example  define the user profile.
3. After this we establish a mechanism to identify the user in a unique way, because not all of the visitors of the website will be members.
4. After indentifying the users uniquely we will notice his preferences and store them in profile provider.
The default settings of profile only authenticates the user who are memebers and regularly visiting the website but we have to configure it for anonymous users or guest visitors.
The profile provider specifies the store where the user preferences are stored. Typically this is database. This needs to be done in the web.config file.
Following is an example
<profile>
<providers>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</profile>
The configuration shows the default profile provider which is local database placed in the App_Data directory of the website. If we need to specify the custom profile provider then we need to specify the connectionString intead of connectionStringName to use the desired database.
Also, we will be needing to set the database to accept and save the profile related data. this is done by running the aspnet_regsql command against the database which will to be used to save the profile data.
After configuring the profile provider, we have to specify the user data that we need to save. We do this by having the properties in the provider element of web.config.
Following is an example
<profile>
<properties>
<add name="Name" allowAnonymous="true"/>
<add name="VisitedOn" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>
The allowAnonymous="true" specifies that the anonymous users will be able to save their profile information. To work this properly we need to specify <anonymousIdentification enabled="true"/> in the web.config file.
After completing this successfully we are able to save all properties we need to track as the user profile information and it works for authenticated as well as anonymous users.
Following is an example of accessing the profile property
string name = Profile.Name;         
DateTime lastVisited = Profile.VisitedOn;
Following is an example of setting the profile property
Profile.Name = TextBox1.Text;
Profile.VisitedOn = DateTime.Now;
Profile.Save();
Profile functionality differs from cokkies in a way that if the user deletes the cookies then the info stored in cookie will be lost.

For further question please mail: brainstormiert@gmail.com

ASP.Net Session

Session
HTTP is stateless protocol which means that server treats each request independently, session enables the user to save and retrieve values while user navigates the web app.
The collection of session variables is indexed by the name of the variable or by an integer index. Session variables are created by referring to the session variable by name. You do not have to declare a session variable or explicitly add it to the collection. The following example shows how to create session variables in an ASP.NET page for the first and last name of a user, and set them to values retrieved from TextBox controls.
Session["FirstName"] = FirstNameTextBox.Text;
Session["LastName"] = LastNameTextBox.Text;
Session variables can be any valid .NET Framework type. The following example stores an ArrayList object in a session variable named StockPicks. The value returned by the StockPicks session variable must be cast to the appropriate type when you retrieve it from the SessionStateItemCollection.
// When retrieving an object from session state, cast it to
// the appropriate type.
ArrayList stockPicks = (ArrayList)Session["StockPicks"];
// Write the modified stock picks list back to session state.
Session["StockPicks"] = stockPicks;
Sessions are identified by a unique identifier that can be read by using the SessionID property. When session state is enabled for an ASP.NET application, each request for a page in the application is examined for a SessionID value sent from the browser. If no SessionID value is supplied, ASP.NET starts a new session and the SessionID value for that session is sent to the browser with the response.
By default, SessionID values are stored in a cookie. However, you can also configure the application to store SessionID values in the URL for a "cookieless" session.
A session is considered active as long as requests continue to be made with the same SessionID value. If the time between requests for a particular session exceeds the specified time-out value in minutes, the session is considered expired. Requests made with an expired SessionID value result in a new session.
The text above is taken from Microsoft.
Read More
Save Values in Session State
This example uses the HttpSessionState object to persist values within an individual session.
string firstName = "Jeff";
string lastName = "Smith";
string city = "Seattle";
Session["FirstName"] = firstName;
Session["LastName"] = lastName;
Session["City"] = city;
The text above is taken from Microsoft.
Read More
Read Values from Session State
This example accesses the Item property to retrieve the values in session state.
string firstName = (string)(Session["First"]);
string lastName = (string)(Session["Last"]);
string city = (string)(Session["City"]);
The text above is taken from Microsoft.
Read More

State management is an art which retains user specific info between requests but most of the time the scope of info is global to entire app, To achieve the goal of state management in the app you may mix up the following server side state management options  
For further question please mail: brainstormiert@gmail.com




ASP.Net Application State

HTTP protocol is a stateless protocol which does not help to maintain the state of the page for example when a request is sent to server by client an instance of the page is created and when the server respondes the instance and the value of control(s) is destroyed, there many techniques to maintain the state of the page one of them is Application state
Application state provides info based on application scope, this info is visible and could be used throughout the application. The info is stored in application state and this info is maintained by the server.
An example is when multiple sessions share the data which does not change is the best type of data to use through application state. It is very easy to use because only one copy of the info is good enough to share between multiple pages.
But on the hand it is highly recommended not to store unique values in application state because this will be global to only particular process and each process may have different unique values.

State management is an art which retains user specific info between requests but most of the time the scope of info is global to entire app, To achieve the goal of state management in the app you may mix up the following server-side state management options

For further question please mail: brainstormiert@gmail.com