Saturday, October 10, 2009

Session Types

What are the Session State Modes?

InProc
State Server
SQL Server
InProc Mode
This mode stores the session data in the ASP.NET worker process.
This is the fastest among all of the storage modes.
This mode effects performance if the amount of data to be stored is large.
If ASP.NET worker process recycles or application domain restarts, the session state will be lost.
State Server mode
In this mode, the session state is serialized and stored in memory in a separate process.
State Server can be maintained on a different system.
State Server mode involves overhead since it requires serialization and de-serialization of objects.
State Server mode is slower than InProc mode as this stores data in an external process.
SQL Server Mode
In this storage mode, the Session data is serialized and stored in a database table in the SQL Server database.
This is reliable and secures storage of a session state.
This mode can be used in the web farms.
It involves overhead in serialization and de-serialization of the objects.
SQL Server is more secure than the InProc or the State server mode.

By anil Prasad

Friday, October 9, 2009

JavaScript and Ajax

Ajax

AJAX = Asynchronous JavaScript and XML.
AJAX is based on JavaScript and HTTP requests.
AJAX is a type of programming made popular in 2005 by Google (with Google Suggest).
AJAX is not a new programming language, but a new way to use existing standards.
AJAX Introduction________________________________________
What you should already know
Before you continue you should have a basic understanding of the following:
• HTML / XHTML
• JavaScript
If you want to study these subjects first, find the tutorials on our Home page.
________________________________________
AJAX = Asynchronous JavaScript and XML
AJAX is not a new programming language, but a new technique for creating better, faster, and more interactive web applications.
With AJAX, a JavaScript can communicate directly with the server, with the XMLHttpRequest object. With this object, a JavaScript can trade data with a web server, without reloading the page.
AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages.
The AJAX technique makes Internet applications smaller, faster and more user-friendly.
________________________________________
AJAX is based on Internet standards
AJAX is based on the following web standards:
• JavaScript
• XML
• HTML
• CSS
AJAX is about better Internet-applications
Internet-applications have many benefits over desktop applications; they can reach a larger audience, they are easier to install and support, and easier to develop.
However, Internet-applications are not always as "rich" and user-friendly as traditional desktop applications.
With AJAX, Internet applications can be made richer and more user-friendly.
AJAX XMLHttpRequest
AJAX uses the XMLHttpRequest object
To get or send information from/to a database or a file on the server with traditional JavaScript, you will have to make an HTML form, and a user will have to click the "Submit" button to send/get the information, wait for the server to respond, then a new page will load with the results. Because the server returns a new page each time the user submits input, traditional web applications can run slowly and tend to be less user-friendly.
With AJAX, your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object.
With the XMLHttpRequest object, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background.
________________________________________
The XMLHttpRequest object
By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded!
AJAX was made popular in 2005 by Google (with Google Suggest).
Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions.
The XMLHttpRequest object is supported in all major browsers (Internet Explorer, Firefox, Chrome, Opera, and Safari).
Your first AJAX application
To understand how AJAX works, we will create a small AJAX application.
First we are going to create a standard HTML form with two input fields: Name and Time. The "Name" field will be filled out by the user, and the "Time" field will be filled out with AJAX.
Example explained
1. Create a variable named xmlhttp to hold the XMLHttpRequest object.
2. Try to create the XMLHttpRequest object with xmlhttp=new XMLHttpRequest().
3. If that fails, try xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"). This is for IE6 and IE5.
4. If that fails too, the user has a very outdated browser, and will get an alert stating that the browser doesn't support XMLHTTP.
Note: The code above can be used every time you need to create an XMLHttpRequest object, so just copy and paste it whenever you need it.
The next chapter shows how to use the XMLHttpRequest object to communicate with a server.
AJAX - More about the XMLHttpRequest object
Before sending data off to a server, we will look at three important properties of the XMLHttpRequest object.

The onreadystatechange property
After a request to a server, we need a function to receive the data returned from the server.
The onreadystatechange property stores the function that will process the response from a server. The function is stored in the property to be called automatically.
The following code sets the onreadystatechange property and stores an empty function inside
xmlhttp.onreadystatechange=function()
{
// We are going to write some code here
}
The readyState property
The readyState property holds the status of the server's response.
Each time the readyState property changes, the onreadystatechange function will be executed.
Possible values for the readyState property:
State Description
0 The request is not initialized
1 The request has been set up
2 The request has been sent
3 The request is in process
4 The request is complete
Add an If statement to the onreadystatechange function to test if the response is complete (means that now we can get our data):
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
// Get data from the server's response
}
}
The responseText property
The data sent back from a server can be retrieved with the responseText property.
Now, we want to set the value of the "Time" input field equal to responseText:
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.myForm.time.value=xmlhttp.responseText;
}
}
AJAX - Sending a request to a server
To send off a request to the server, we use the open() and send() methods.
The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously.
The send() method sends the request off to the server. If we assume that the HTML and ASP file are in the same directory, the code would be:
xmlhttp.open("GET","time.asp",true);
xmlhttp.send(null);
Now we must decide when the AJAX function should be executed.
We will let the function run "behind the scenes" when a user types something in the "Name" field:

Name:
Time:


Now we are going to create the server-side script that displays the current time.
The responseText property (explained in the previous chapter) will store the data returned from the server. Here we want to send back the current time.
The code in "time.asp" looks like this:
<%
response.expires=-1
response.write(time)
%>

Note: The response.expires command sets how long time (in minutes) a page will be cached on a browser before it expires. If a user returns to the same page before it expires, the cached version is displayed. response.expires=-1 indicates that the page will never be cached.
Run your first AJAX application