Download - RECENT FAQ'S
-
8/7/2019 RECENT FAQ'S
1/76
1. What is Application pooling?
2. How did u deploy application into IIS Server?
3. What is generic list?
4. What is partial class and which .Net feature it is?
5. Difference between UserDefinedFunction and Stored Procedure?
6. How can u call UDF from ADO.NET?7. What are Triggers?
8. What are views?
9. What are Magic tables and Temporary tables?
10.What is Post Back? What is it drawbacks? How can u handle that?
11.What is stateless ness?
12.How does u kill the Session?
13.What is polymorphism?
14.Did u use Interfaces in Your application?
15.Difference between User control and Custom Control?
16.Features of .Net 4.0?
17.What are the new features of SQL Server 2005?
18.Have u worked with AJAX?
19.What are Nested Master pages?
20.What are sub queries?
21.What is the difference between variable and properties?
22.Can u call the one class constructor in another class?
23.What is Assembly? Types of assemblies?
24.About strong Name and GAC Util?
25.Page Life Cycle?
26.In Which event you will put the code to call the style sheet dynamically?
27.What is XSLT?28.What are JOINS AND Types of JOINS?
29.Did u face any performance issues with ENTERPRISE LIBRARY?
30.What is sealed class?
31.Did u find any advantage of Telerik RAD Grid over DataGrid control of
ASP.NET?
32.What is Execute. Scalar and Execute.NonQuery ();?
33.How does u handle errors in application?
34.What are Nullables?
35.How can u handle exceptions in UDF?
36.Dataset update changes accept changes and reject changes? How can uavoid concurrency?
37.Delegates in USER CONTROL?
38.Delegates and events?
39.What is Authentication and Authorization?
40.Why do u use telirik controls?
41.What are the .net 3.5 features used in your project?
42.How do u store image in a database?
-
8/7/2019 RECENT FAQ'S
2/76
43.Procedure to upload a file in asp.net?
44.What are Data binding controls in .net 3.5? Which is better in performance
wise?
45.DataSet Methods and Properties?
46.Boxing and unboxing?
47.Overloading and overriding?48.What is XSLT?
49.State Management Techniques?
50.Return type of execute. Nonquery(); and execute.scalar?
51.Difference between char,Varchar and nvarchar datatypes?
52.How can u find the value of a textbox using javascript?
53.Difference between normal query and stored procedure?
54.What is base page?
55.Where are session variables stored?
56.What are the events in global asax?
57.Object reference not set to an instance of a object?
58.Difference between client side and server side validations?
59.Drawbacks of client side validation?
60.Difference between String and String Builder?
61.String is value type or reference type?
62.What is static class,static method,static constructor?
63.Difference between Const and Read only?
64.Difference between 3-tier and 3 layered architecture?
65.What is Abstract Class?
66.What is Interface?
67.Can u declare Static method in Abstract class?
68.Difference between Machine and Webconfig?69.ViewState?
70.Java script Validation for a textbox which is placed in a grid view?
ANSWERS:
DIFFERENCE BETWEEN STRING AND STRING BUILDER IN C#.NET?
Re: What is the Main difference between String and
StringBuilder and why do we use StringBuilder.
Answe
r
# 3
String are Immutable (Not Modifiable). If
you try to modifythe string it actually creates a new
string and the oldstring will be then ready for garbage
collection.
StringBuilder when instantiated, creates anew string with
predefined capacity and upto that capacity
0 Sande
ep
Soni
http://www.allinterview.com/viewpost/86828.htmlhttp://www.allinterview.com/viewpost/86828.html -
8/7/2019 RECENT FAQ'S
3/76
it can
accodomate string without needing tocreate a new memory
location for the string....i mean it is
modifiable and can
also grow as and when needed.
When the string needs to be modifiedfrequently, preferably
use StringBuilder as its optimized for
such situations.
Re: What is the Main difference between String and
StringBuilder and why do we use StringBuilder.
Answe
r# 4
Both String and StringBuilder are classes
used tohandle the strings.
The most common operation with a
string is
concatenation. This activity has to be
performed veryefficiently. When we use the "String"
object to concatenatetwo strings, the first string is combined
to the other
string by creating a new copy in the
memory as a stringobject, and then the old string is
deleted. This process isa little long. Hence we say "Strings are
immutable".
When we make use of the
"StringBuilder" object, the
Append method is used. This means, aninsertion is done on
the existing string. Operation onStringBuilder object is
faster than String operations, as the copy
is done to the
same location. Usage of StringBuilder is
more efficient incase large amounts of string manipulationshave to be performed.
STATIC CLASS: A static class is basically the same as a non-static class, but there is onedifference: a static class cannot be instantiated. In other words, you cannot use thenewkeywordto create a variable of the class type. Because there is no instance variable, you access the
http://www.allinterview.com/viewpost/87890.htmlhttp://msdn.microsoft.com/en-us/library/98f28cdx.aspxhttp://msdn.microsoft.com/en-us/library/51y09td4.aspxhttp://msdn.microsoft.com/en-us/library/51y09td4.aspxhttp://msdn.microsoft.com/en-us/library/51y09td4.aspxhttp://www.allinterview.com/viewpost/87890.htmlhttp://msdn.microsoft.com/en-us/library/98f28cdx.aspxhttp://msdn.microsoft.com/en-us/library/51y09td4.aspx -
8/7/2019 RECENT FAQ'S
4/76
members of a static class by using the class name itself. For example, if you have a static classthat is named UtilityClass that has a public method named MethodA, you call the method asshown in the following example:
VBC#
C++F#JScript
CopyUtilityClass.MethodA();
A static class can be used as a convenient container for sets of methods that just operate oninput parameters and do not have to get or set any internal instance fields. For example, inthe .NET Framework Class Library, the static System.Math class contains methods that performmathematical operations, without any requirement to store or retrieve data that is unique to aparticular instance of the Math class. That is, you apply the members of the class by specifyingthe class name and the method name, as shown in the following example.
Copy
double dub = -3.14;Console.WriteLine(Math.Abs(dub));Console.WriteLine(Math.Floor(dub));Console.WriteLine(Math.Round(Math.Abs(dub)));
// Output:// 3.14// -4// 3
As is the case with all class types, the type information for a static class is loaded by the .NET
Framework common language runtime (CLR) when the program that references the class isloaded. The program cannot specify exactly when the class is loaded. However, it is guaranteedto be loaded and to have its fields initialized and its static constructor called before the class isreferenced for the first time in your program. A static constructor is only called one time, and astatic class remains in memory for the lifetime of the application domain in which your programresides.
NoteTo create a non-static class that allows only one instance of itself to be created, see
Implementing Singleton in C#.
The following list provides the main features of a static class:
Contains only static members. Cannot be instantiated. Is sealed. Cannot containInstance Constructors.
Creating a static class is therefore basically the same as creating a class that contains only staticmembers and a private constructor. A private constructor prevents the class from beinginstantiated. The advantage of using a static class is that the compiler can check to make surethat no instance members are accidentally added. The compiler will guarantee that instances ofthis class cannot be created.
http://tmp/svfin.tmp/javascript:%20CodeSnippet_SetLanguage('Visual%20Basic');http://tmp/svfin.tmp/javascript:%20CodeSnippet_SetLanguage('Visual%20C++');http://tmp/svfin.tmp/javascript:%20CodeSnippet_SetLanguage('JScript');http://tmp/svfin.tmp/javascript:CodeSnippet_CopyCode('CodeSnippetContainerCode0');http://msdn.microsoft.com/en-us/library/system.math.aspxhttp://msdn.microsoft.com/en-us/library/system.math.aspxhttp://go.microsoft.com/fwlink/?LinkID=100567http://msdn.microsoft.com/en-us/library/k6sa6h87.aspxhttp://msdn.microsoft.com/en-us/library/k6sa6h87.aspxhttp://tmp/svfin.tmp/javascript:%20CodeSnippet_SetLanguage('Visual%20Basic');http://tmp/svfin.tmp/javascript:%20CodeSnippet_SetLanguage('Visual%20C++');http://tmp/svfin.tmp/javascript:%20CodeSnippet_SetLanguage('JScript');http://tmp/svfin.tmp/javascript:CodeSnippet_CopyCode('CodeSnippetContainerCode0');http://msdn.microsoft.com/en-us/library/system.math.aspxhttp://msdn.microsoft.com/en-us/library/system.math.aspxhttp://go.microsoft.com/fwlink/?LinkID=100567http://msdn.microsoft.com/en-us/library/k6sa6h87.aspx -
8/7/2019 RECENT FAQ'S
5/76
Static classes are sealed and therefore cannot be inherited. They cannot inherit from any classexcept Object. Static classes cannot contain an instance constructor; however, they can contain astatic constructor. Non-static classes should also define a static constructor if the class containsstatic members that require non-trivial initialization. For more information, seeStaticConstructors (C# Programming Guide).
STATIC METHODS: Are you familiar with OOP? In OOP, static objects or members of a class that can be
accessed directly from the class, while non-static members can only be accessed from the instance it belongs to.
C# follows a similar principle for the methods. The static methods can by accessed directly from the class, while non-
static methods (or instance methods as I like to call them) have to be accessed from an instance. That is why
instatiating needs to be done for instance methods, while for static methods it's just not needed, and furthermore
impractical (see below).
In OOP, static variables are used for values which cannot be stored by an instance variable. Example: supposed you
wanted to keep a count of how many instances of a class exists? How would you store that in a single instance?
The methods use a similar principle. They should be used for procedures for which it is impractical to do within an
instance of a class. I tend to use them for broad procedures (not a technical term), meaning those that do not require
me to instantiate an object. Example, adding two parameters. (This usage may or may not be correct, but I believe it
is)
However, if you wanted to add two properties of an object, the method cannot be static, because as you would soon
realize, static methods cannot access instance methods or variables within a class. Of course that makes sense
because that static method would not know which instance of the class the get these from unless it were told, since it
is not part of an instance itself)
STATIC CONSTRUCTOR:
A Constructor is usually used to initialize data. However Static Constructor is used toinitialize only static members. Here I am just talking about the Constructors. How they getinitialized and how they behave.
Things to know about Static Constructor
1. It is used to initialize static data members.
2. Can't access anything but static members.
3. Can't have parameters
4. Can't have access modifiers like Public, Private or Protected.
Now once you understand the above points, you can appreciate the difference betweenStatic Class and Unstatic Class
1. Static Class cannot be instantiated unlike the unstatic class. You should directlyaccess its Method via the ClassName.MethodName
2. A Program can't tell when it is going to load static class but its definitely loadedbefore the call.
3. A Static class will always have the static constructor and its called only once sinceafter that its in the memory for its lifetime.
4. A Static class can contain only static members. So all the members and functionshave to be static.
http://msdn.microsoft.com/en-us/library/system.object.aspxhttp://msdn.microsoft.com/en-us/library/system.object.aspxhttp://msdn.microsoft.com/en-us/library/k9x6w0hc.aspxhttp://msdn.microsoft.com/en-us/library/k9x6w0hc.aspxhttp://msdn.microsoft.com/en-us/library/k9x6w0hc.aspxhttp://msdn.microsoft.com/en-us/library/system.object.aspxhttp://msdn.microsoft.com/en-us/library/k9x6w0hc.aspxhttp://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx -
8/7/2019 RECENT FAQ'S
6/76
-
8/7/2019 RECENT FAQ'S
7/76
In this example, the class MyDerivedC is derived from an abstract class MyBaseC. The abstractclass contains an abstract method, MyMethod(), and two abstract properties, GetX() andGetY().
Copy// abstract_keyword.cs// Abstract Classes
using System;abstract class MyBaseC // Abstract class{
protected int x = 100;protected int y = 150;public abstract void MyMethod(); // Abstract method
public abstract int GetX // Abstract property{
get;}
public abstract int GetY // Abstract property
{get;
}}
class MyDerivedC: MyBaseC{
public override void MyMethod(){
x++;y++;
}
public override int GetX // overriding property{get{
return x+10;}
}
public override int GetY // overriding property{
get{
return y+10;
}}
public static void Main(){
MyDerivedC mC = new MyDerivedC();mC.MyMethod();Console.WriteLine("x = {0}, y = {1}", mC.GetX, mC.GetY);
}}
-
8/7/2019 RECENT FAQ'S
8/76
Output
Copyx = 111, y = 161
In the preceding example, if you attempt to instantiate the abstract class by using a statementlike this:
CopyMyBaseC mC1 = new MyBaseC(); // Error
you will get the following error message:
CopyCannot create an instance of the abstract class 'MyBaseC'.
#2
This is a detailed analysis of Abstract classes and methods in C# with some concreteexamples.
The keyword abstract can be used with both classes and methods in C# to declare them as
abstract.The classes, which we can't initialize, are known as abstract classes. They provide onlypartial implementations. But another class can inherit from an abstract class and can createtheir instances.
For example, an abstract class with a non-abstract method.
using System;abstractclass MyAbs{publicvoid NonAbMethod(){Console.WriteLine("Non-Abstract Method");}}class MyClass : MyAbs{}class MyClient{publicstaticvoid Main(){
//MyAbs mb = new MyAbs();//not possible to create an instanceMyClass mc = new MyClass();mc.NonAbMethod();// Displays 'Non-Abstract Method'}
}
An abstract class can contain abstract and non-abstract methods. When a class inheritsfrom an abstract, the derived class must implement all the abstract methods declared in thebase class.
An abstract method is a method without any method body. They are implicitly virtual in C#.
using System;
-
8/7/2019 RECENT FAQ'S
9/76
abstractclass MyAbs{publicvoid NonAbMethod(){Console.WriteLine("Non-Abstract Method");}
publicabstractvoid AbMethod();// An abstract method}class MyClass : MyAbs//must implement base class abstract methods{publicoverridevoid AbMethod(){Console.WriteLine("Abstarct method");}}class MyClient{publicstaticvoid Main(){
MyClass mc = new MyClass();mc.NonAbMethod();mc.AbMethod();}}
But by declaring the derived class also abstract, we can avoid the implementation of all orcertain abstract methods. This is what is known as partial implementation of an abstractclass.
using System;abstractclass MyAbs
{publicabstractvoid AbMethod1();publicabstractvoid AbMethod2();}
//not necessary to implement all abstract methods//partial implementation is possibleabstractclass MyClass1 : MyAbs{publicoverridevoid AbMethod1(){Console.WriteLine("Abstarct method #1");}}
class MyClass : MyClass1{publicoverridevoid AbMethod2(){Console.WriteLine("Abstarct method #2");}}class MyClient{
-
8/7/2019 RECENT FAQ'S
10/76
publicstaticvoid Main(){MyClass mc = new MyClass();mc.AbMethod1();mc.AbMethod2();}
}
In C#, an abstract class can inherit from another non-abstract class. In addition to themethods it inherited from the base class, it is possible to add new abstract and non-abstractmethods as showing below.
using System;class MyClass1// Non-Abstract class{publicvoid Method1(){Console.WriteLine("Method of a non-abstract class");}
}abstractclass MyAbs : MyClass1// Inherits from an non-abstract class{publicabstractvoid AbMethod1();}class MyClass : MyAbs//must implement base class abstract methods{publicoverridevoid AbMethod1(){Console.WriteLine("Abstarct method #1 of MyClass");}}
class MyClient{publicstaticvoid Main(){MyClass mc = new MyClass();mc.Method1();mc.AbMethod1();}}
An abstract class can also implement from an interface. In this case we must providemethod body for all methods it implemented from the interface.
using System;interface IInterface{void Method1();}abstractclass MyAbs : IInterface{publicvoid Method1(){
-
8/7/2019 RECENT FAQ'S
11/76
Console.WriteLine("Method implemented from the IInterface");}}class MyClass : MyAbs//must implement base class abstract method{}
class MyClient{publicstaticvoid Main(){MyClass mc = new MyClass();mc.Method1();}}}}
We can't use the key word abstract along with sealed in C#, since a sealed class can't beabstract.
The abstract methods are implicitly virtual and hence they can't mark explicitly virtual inC#.
For example
using System;abstractclass MyAbs{publicabstractvoid AbMethod1();publicabstractvoid AbMethod2();}
class MyClass1 : MyAbs{publicoverridevoid AbMethod1(){Console.WriteLine("Abstarct method #1 of MyClass1");}publicoverridevoid AbMethod2(){Console.WriteLine("Abstarct method #2 of MyClass1");}}class MyClient{publicstaticvoid Main()
{MyAbs ma1 = new MyClass1();// Polymorphismma1.AbMethod1();ma1.AbMethod2();}}
INTERFACES:
-
8/7/2019 RECENT FAQ'S
12/76
An interface is a structure that declares certain methods andproperties (like a class), but doesn't provide implementations of them.So, you can (almost) never create an instance of an interface with'new', as it's meaningless - the resulting object can't actually *do*anything.
Instead, you define a class that implements the interface - that is,
the interface name is included in its list of base classes, and theclass is then required by the compilerto implement all of thefunctions declared in the interface.
The idea is that you can then define functions that take as a parameteran object of arbitrary type, but which is known to implement theinterface (declaring a variable of interface type means it is areference to some object of a class implementing the interface); then,you can use the methods that you know must exist in the class (thosedefined in the interface) to do whatever you want, without concerningyourself with what other methods/functionality the object may have.
So, for example, the IEnumerable interface in .NET is implemented by
collection classes, and it means that an object of any classimplementing it, regardless of how the collection itself actuallyworks, can be used as a 'foreach' variable and a few other things, asthe compiler then knows that the object passed is guaranteed to havecertain functionality.
To define your own interface, use the 'interface' keyword, and declarethe members like for a class (but without function bodies). Then, youcould have a function that takes as a parameter an object implementingthe interface, which could actually be an instance of any class youwrite that implements the interface. e.g. [syntax may be *slightly*wrong as I haven't tried compiling this]:
interface ISortable
{void SortData();bool IsSorted{get;}}
class SomethingSortable : ISortable{void SortData() // if we don't override this function our classwon't compile{[...]
}bool IsSorted{get{return ...;}}}
http://www.velocityreviews.com/forums/t116400-interfaces-in-c-net.htmlhttp://www.velocityreviews.com/forums/t116400-interfaces-in-c-net.htmlhttp://www.velocityreviews.com/forums/t116400-interfaces-in-c-net.htmlhttp://www.velocityreviews.com/forums/t116400-interfaces-in-c-net.htmlhttp://www.velocityreviews.com/forums/t116400-interfaces-in-c-net.htmlhttp://www.velocityreviews.com/forums/t116400-interfaces-in-c-net.htmlhttp://www.velocityreviews.com/forums/t116400-interfaces-in-c-net.html -
8/7/2019 RECENT FAQ'S
13/76
Now we could have a method somewhere like this:
object BinarySearch(ISortable lst){lst.SortData(); // we know this method has to exist in anyobject passed}
This C# Tutorial deals with interfaces in C# .Net. An Interface is a reference type and it contains only
abstract members. Interface's members can be Events, Methods, Properties and Indexers. But the
interface contains only declaration for its members. Any implementation must be placed in class that
realizes them. The interface can't contain constants, data fields, constructors, destructors and static
members. All the member declarations inside interface are implicitly public.
Defining an Interface:
Let us look at a simple example for c# interfaces. In this example interface declares base functionality of
node object.
interface INode
{
string Text
{
get;
set;
}
object Tag
{
get;
set;
}
int Height
{
get;
set;
}
int Width
{
get;
set;
}
float CalculateArea();
}
The above INode interface has declared a few abstract properties and function which should be
implemented by the derived classes.
//Sample for Deriving a class using a C# .Net interface - c# tutorial
public class Node : INode
{
public Node()
-
8/7/2019 RECENT FAQ'S
14/76
{}
public string Text
{
get
{
return m_text;}
set
{
m_text = value;
}
}
private string m_text;
public object Tag
{
get
{
return m_tag;
}
set
{
m_tag = value;
}
}
private object m_tag = null;
public int Height
{
get
{
return m_height;
}
set
{
m_height = value;
}
}
private int m_height = 0;
public int Width{
get
{
return m_width;
}
set
-
8/7/2019 RECENT FAQ'S
15/76
{
m_width = value;
}
}
private int m_width = 0;
public float CalculateArea()
{
if((m_width
-
8/7/2019 RECENT FAQ'S
16/76
Example of Run Time Polymorphism
Method Overriding
- Method overriding occurs when child class declares a method that has the sametype arguments as a method declared by one of its superclass.- Method overriding forms Run-time polymorphism.- Note: By default functions are not virtual in C# and so you need to write virtualexplicitly. While by default in Java each function are virtual.- Example of Method Overriding:Class parent{virtual void hello(){ Console.WriteLine(Hello from Parent); }}
Class child : parent
{override void hello(){ Console.WriteLine(Hello from Child); }}
static void main(){parent objParent = new child();objParent.hello();}
//Output
Hello from Child.
What is Polymorphism?
Polymorphism is one of the primary characteristics (concept) of object-oriented
programming.
Poly means many and morph means form. Thus, polymorphism refers to being
able to use many forms of a type without regard to the details.
Polymorphism is the characteristic of being able to assign a different meaning
specifically, to allow an entity such as a variable, a function, or an object to
have more than one form.
Polymorphism is the ability to process objects differently depending on their
data types.
-
8/7/2019 RECENT FAQ'S
17/76
Polymorphism is the ability to redefine methods for derived classes.
Types of Polymorphism
Compile time Polymorphism
Run time Polymorphism
Compile time Polymorphism
Compile time Polymorphism also known as method overloading
Method overloading means having two or more methods with the same name
but with different signatures
Example of Compile time polymorphism
Run time Polymorphism
Run time Polymorphism also known as method overriding
-
8/7/2019 RECENT FAQ'S
18/76
Method overriding means having two or more methods with the same name ,
same signature but with different implementation
Example of Run time Polymorphism
You can find source code at the bottom of this article.
What is an Abstraction?
. Abstraction is thinking about something a certain way
. Abstraction is the representation of only the essential features of an object and hiding
un essential features of an object.
. Through Abstraction all relevant data can be hide in order to reduce complexity and
increase efficiency
. Abstraction is simplifying complex reality by modeling classes appropriate to the
problem
. Abstraction-outer layout, used in terms of design
. Encapsulation protects abstraction.
. It taking required data and hiding the unwanted data.
-
8/7/2019 RECENT FAQ'S
19/76
In this above example abstraction shows only necessary details of car or shows onlynecessary details to drive a car like rear view mirror, gear, clutch, steering And hidesinternal detail of car like Piston, crankshaft, carburetors, gas turbines etc which isencapsulation for a car.
Abstraction shows only required data and hides unwanted data.
Difference between Encapsulation and Abstraction
1. Abstraction solves the problemin the design level
1. Encapsulation solves the problem in theimplementation level
2. Abstraction is used for hiding
the unwanted data and giving
relevant data
2. Encapsulation means hiding the code
and data in to a single unit to protect the
data from outside world
3. Abstraction is a technique that 3. Encapsulation is the technique for
-
8/7/2019 RECENT FAQ'S
20/76
helps to identify which specific
information should be visible and
which information should be
hidden.
packaging the information in such a way
as to hide what should be hidden, and
make visible what is intended to be visible.
In this above example abstraction shows only necessary details of car or shows onlynecessary details to drive a car like rear view mirror, gear, clutch, steering And hidesinternal detail of car like Piston, crankshaft, carburetors, gas turbines etc which isencapsulation for a car
Abstraction shows only required data and hides unwanted data .
-
8/7/2019 RECENT FAQ'S
21/76
In above example which shows encapsulated detail of a car which is not necessary toexpose to outside world and make visible what is intended to be visible.
What is Encapsulation?
Encapsulation is one of the fundamental principles of object-oriented
programming.
Encapsulation is a process of hiding all the internal details of an object from the
outside world
Encapsulation is the ability to hide its data and methods from outside the world
and only expose data and methods that are required
Encapsulation is a protective barrier that prevents the code and data being
randomly accessed by other code or by outside the class
Encapsulation gives us maintainability, flexibility and extensibility to our code.
Encapsulation makes implementation inaccessible to other parts of the program
and protect from whatever actions might be taken outside the function or class.
Encapsulation provides a way to protect data from accidental corruption
-
8/7/2019 RECENT FAQ'S
22/76
Encapsulation hides information within an object
Encapsulation is the technique or process of making the fields in a class private
and providing access to the fields using public methods
Encapsulation gives you the ability to validate the values before the object user
change or obtain the value
Encapsulation allows us to create a "black box" and protects an objects internal
state from corruption by its clients.
Two ways to create a validation process.
Using Accessors and Mutators
Using properties
-
8/7/2019 RECENT FAQ'S
23/76
In this example _employeeid and _salary is private fields and providing access to thefields using public methods (SetEmployeeID,GetEmployeeID,SetSalary,GetSalary)
In this example _employeeid and _salary is private fields and providing access to thefields using public methods (EmployeeID,Salary)
Benefits of Encapsulation
In Encapsulation fields of a class can be read-only or can be write-only
A class can have control over in its fields
A class can change data type of its fields anytime but users of this class do not
need to change any code
What is Access Modifier?
Access modifiers determine the extent to which a variable or method can be accessedfrom another class or object
-
8/7/2019 RECENT FAQ'S
24/76
The following five accessibility levels can be specified using the access modifiers
Private
Protected
Internal
Protected internal
Public
1. What is Private access modifier?
In OOP Attributes, Methods, Properties, Constructors declared with "private" accessmodifier get access or visible only to members of current class
For e.g.: Let's take class BankDetail with access modifier "private"
class BankDetail{
private string _employeename;
private int _accountnumber;private double _balanceamount;
private string EmployeeName
{
set{
_employeename = value;}
get
{
return _employeename;}
}
private int AccountNumer{
set
{
_accountnumber = value;}
get { return _accountnumber; }
}
private double BalanceAmount
{set { _balanceamount = value; }
get { return _balanceamount; }}
private void DisplayDetail()
-
8/7/2019 RECENT FAQ'S
25/76
{Console.WriteLine("BankDetail for " + _employeename +
"Account Number " + _accountnumber
+ " with Balance Amount is " + _balanceamount);
}
}
Create another class "clsShowDetails"
Now inside class "clsShowDetails" create object of class BankDetail
BankDetail objBank = new BankDetail();
Fron Object objBank if we are trying to access methods,properties of class BankDetailwe cannot access them due to the protction level of "private" access modifier
public class clsShowDetails
{BankDetail objBank = new BankDetail();
public void getDetails(){objBank.DisplayDetail();
}
}From class "clsShowDetail"
public void getDetails(){
objBank.DisplayDetail();}
We will get error message
(BankDetail.DisplayDetail() is inaccessible due to protection level)
This means we cannot access Attributes, Methods, Properties, Constructors declaredwith "private" access modifier outside of class but can get access or visible only tomembers of current class
2. What is protected access modifier?
In OOP Attributes, Methods, Properties, Constructors declared with "protected" accessmodifier get access or visible only to members of current class as well as to membersof derived class.
For e.g.: Let's take class BankDetail with access modifier "protected"
class BankDetail{
protected string _employeename;
protected int _accountnumber;
protected double _balanceamount;
protected string EmployeeName
{
-
8/7/2019 RECENT FAQ'S
26/76
set{
_employeename = value;
}
get{
return _employeename;}
}protected int AccountNumer
{
set
{_accountnumber = value;
}get { return _accountnumber; }
}
protected double BalanceAmount
{set { _balanceamount = value; }
get { return _balanceamount; }}
protected void DisplayDetail(){
Console.WriteLine("BankDetail for " + _employeename +
"Account Number " + _accountnumber
+ " with Balance Amount is " + _balanceamount);}
}
Create another class "clsShowDetails"
Now inside class "clsShowDetails" create object of class BankDetail
BankDetail objBank = new BankDetail();
public class clsShowDetails:BankDetail
{
public void getDetails()
{
DisplayDetail();}
}From class "clsShowDetail"
public void getDetails()
{
DisplayDetail();
}
We will get no error message
-
8/7/2019 RECENT FAQ'S
27/76
This means we can access Attributes, Methods, Properties, Constructors declared with"protected" access modifier in derived class
3. What is internal access modifier?
In OOP Attributes, Methods, Properties, Constructors declared with "internal" accessmodifier get access or visible only to members of current project or in currentnamespace
For e.g.: Let's take class BankDetail with access modifier "internal"
class BankDetail
{
internal string _employeename;
internal int _accountnumber;internal double _balanceamount;
internal string EmployeeName{
set{
_employeename = value;}
get
{
return _employeename;}
}
internal int AccountNumer{
set{
_accountnumber = value;}
get { return _accountnumber; }}
internal double BalanceAmount
{set { _balanceamount = value; }
get { return _balanceamount; }}
internal void DisplayDetail(){
Console.WriteLine("BankDetail for " + _employeename +
"Account Number " + _accountnumber+ " with Balance Amount is " + _balanceamount);
}}
Add New Item in the same project
-
8/7/2019 RECENT FAQ'S
28/76
Create another class "clsShowDetails" in Class2.cs file
Now inside class "clsShowDetails" create object of class BankDetail
BankDetail objBank = new BankDetail();
public class clsShowDetails
{
BankDetail objBank = new BankDetail();
public void getDetails()
{objBank.DisplayDetail();
}
}
From class "clsShowDetails"public void getDetails()
{DisplayDetail();
}
We will get no error message
This means we can access Attributes, Methods, Properties, and Constructors declaredwith "internal" access or visible only to members of current project or in current
namespace
4. What is protected internal access modifier?
In OOP Attributes, Methods, Properties, Constructors declared with "protected internal"access modifier get access or visible only to members of current project or in currentnamespace and also to members of derived class
http://www.dotnetspark.com/kb/848-access-modifiers-c-sharp.aspxhttp://www.dotnetspark.com/kb/848-access-modifiers-c-sharp.aspx -
8/7/2019 RECENT FAQ'S
29/76
5. What is public access modifier?
In OOP Attributes, Methods, Properties, Constructors declared with "public" accessmodifier get access or visible to all members of classes and projects
class BankDetail{
public string _employeename;public int _accountnumber;
public double _balanceamount;public string EmployeeName
{
set
{_employeename = value;
}get
{
return _employeename;
}
}public int AccountNumer{
set{
_accountnumber = value;
}
get { return _accountnumber; }}
public double BalanceAmount{
set { _balanceamount = value; }get { return _balanceamount; }
}
public void DisplayDetail(){
Console.WriteLine("BankDetail for " + _employeename +"Account Number " + _accountnumber
+ " with Balance Amount is " + _balanceamount);
}
}
Create another class "clsShowDetails"
Now inside class "clsShowDetails" create object of class BankDetail
BankDetail objBank = new BankDetail();
public class clsShowDetails
{
BankDetail objBank = new BankDetail();
public void getDetails(){
-
8/7/2019 RECENT FAQ'S
30/76
objBank.DisplayDetail();}
}
From class "clsShowDetail"
public void getDetails()
{objBank.DisplayDetail();
}
We will get no error message
Let's try to access "public" access modifier with another example
Add New Item in the same project
Create another class "clsShowDetails"
Now inside class "clsShowDetails" create object of class BankDetail
BankDetail objBank = new BankDetail();
public class clsShowDetails
{BankDetail objBank = new BankDetail();
public void getDetails()
{objBank.DisplayDetail();
}
}From class "clsShowDetail"
public void getDetails(){
objBank.DisplayDetail();
}
-
8/7/2019 RECENT FAQ'S
31/76
We will get no error message
This means "public" access modifier is access or visible to all members of classes andprojects.
DIFFERENCE BETWEEN VIRTUAL METHOD AND ABSTRACT METHOD?
VIRTUAL METHOD CAN BE OVERRIDDEN IN ANY OF ITS DERIVED CLASS AND ABSTRACT METHOD MUSTBE OVERRIDDEN IN ANY OF THE NON ABSTRACT CLASS
STRUCT IS VALUE TYPE AND CLASS IS REFERENCE TYPE.
Difference between Const and ReadOnly:
Const:
1. Cannot be static2. The value is evaluated at compile time
3. It is initialized at declaration only
4. The const keyword is used for compile-time constant
ReadOnly:
1. Can be either instance-level or static
2. Value is evaluated at runtime
3. Readonly keyword is used for runtime constants .
State Management Techniques in ASP.NET
This article discusses various options for state management for web applications developedusing ASP.NET. Generally, web applications are based on stateless HTTP protocol whichdoes not retain any information about user requests. In typical client and servercommunication using HTTP protocol, page is created each time the page is requested.
Developer is forced to implement various state management techniques when developingapplications which provide customized content and which "remembers" the user.
Here we are here with various options for ASP.NET developer to implement statemanagement techniques in their applications. Broadly, we can classify state managementtechniques as client side state management or server side state management. Eachtechnique has its own pros and cons. Let's start with exploring client side state management
options.
Client side State management Options:
ASP.NET provides various client side state management options like Cookies, QueryStrings(URL), Hidden fields, View State and Control state (ASP.NET 2.0). Let's discuss each ofclient side state management options.
-
8/7/2019 RECENT FAQ'S
32/76
Bandwidth should be considered while implementing client side state management optionsbecause they involve in each roundtrip to server. Example: Cookies are exchanged between
client and server for each page request.
Cookie:
A cookie is a small piece of text stored on user's computer. Usually, information is stored as
name-value pairs. Cookies are used by websites to keep track of visitors. Every time a uservisits a website, cookies are retrieved from user machine and help identify the user.
Let's see an example which makes use of cookies to customize web page.
if(Request.Cookies["UserId"] != null)lbMessage.text = "Dear" + Request.Cookies["UserId"].Value + ", Welcome to our
website!";else
lbMessage.text = "Guest,welcome to our website!";
If you want to store client's information use the below code
Response.Cookies["UserId"].Value=username;
Advantages:
Simplicity
Disadvantages:
Cookies can be disabled on user browsers
Cookies are transmitted for each HTTP request/response causing overhead onbandwidth
Inappropriate for sensitive data
Hidden fields:
Hidden fields are used to store data at the page level. As its name says, these fields are notrendered by the browser. It's just like a standard control for which you can set itsproperties. Whenever a page is submitted to server, hidden fields values are also posted toserver along with other controls on the page. Now that all the asp.net web controls havebuilt in state management in the form of view state and new feature in asp.net 2.0 controlstate, hidden fields functionality seems to be redundant. We can still use it to storeinsignificant data. We can use hidden fields in ASP.NET pages using following syntax
protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1;
//to assign a value to Hidden fieldHidden1.Value="Create hidden fields";
//to retrieve a value
string str=Hidden1.Value;
Advantages:
Simple to implement for a page specific data
Can store small amount of data so they take less size.
Disadvantages:
Inappropriate for sensitive data
-
8/7/2019 RECENT FAQ'S
33/76
Hidden field values can be intercepted(clearly visible) when passed over a network
View State:
View State can be used to store state information for a single user. View State is a built infeature in web controls to persist data between page post backs. You can set View Stateon/off for each control using EnableViewState property. By default, EnableViewState
property will be set to true. View state mechanism poses performance overhead. View stateinformation of all the controls on the page will be submitted to server on each post back. Toreduce performance penalty, disable View State for all the controls for which you don't needstate. (Data grid usually doesn't need to maintain state). You can also disable View State forthe entire page by adding EnableViewState=false to @page directive. View state data isencoded as binary Base64 - encoded which add approximately 30% overhead. Care must betaken to ensure view state for a page is smaller in size. View State can be used usingfollowing syntax in an ASP.NET web page.
// Add item to ViewStateViewState["myviewstate"] = myValue;
//Reading items from ViewState
Response.Write(ViewState["myviewstate"]);
Advantages:
Simple for page level data
Encrypted
Can be set at the control level
Disadvantages:
Overhead in encoding View State values
Makes a page heavy
Query strings:Query strings are usually used to send information from one page to another page. They arepassed along with URL in clear text. Now that cross page posting feature is back in asp.net2.0, Query strings seem to be redundant. Most browsers impose a limit of 255 characters onURL length. We can only pass smaller amounts of data using query strings. Since Querystrings are sent in clear text, we can also encrypt query values. Also, keep in mind thatcharacters that are not valid in a URL must be encoded using Server.UrlEncode.
Let's assume that we have a Data Grid with a list of products, and a hyperlink in the gridthat goes to a product detail page, it would be an ideal use of the Query String to includethe product ID in the Query String of the link to the product details page (for example,productdetails.aspx?productid=4).
When product details page is being requested, the product information can be obtained byusing the following codes:
string productid;productid=Request.Params["productid"];
Advantages:
Simple to Implement
Disadvantages:
-
8/7/2019 RECENT FAQ'S
34/76
Human Readable
Client browser limit on URL length
Cross paging functionality makes it redundant
Easily modified by end user
Control State:
Control State is new mechanism in ASP.NET 2.0 which addresses some of the shortcomingsof View State. Control state can be used to store critical, private information across postbacks. Control state is another type of state container reserved for controls to maintain theircore behavioral functionality whereas View State only contains state to maintain control'scontents (UI). Control State shares same memory data structures with View State. ControlState can be propagated even though the View State for the control is disabled. Forexample, new control Grid View in ASP.NET 2.0 makes effective use of control state tomaintain the state needed for its core behavior across post backs. Grid View is in no wayaffected when we disable View State for the Grid View or entire page
Server Side State management:
As name implies, state information will be maintained on the server. Application, Session,
Cache and Database are different mechanisms for storing state on the server.
Care must be taken to conserve server resources. For a high traffic web site with large
number of concurrent users, usageof sessions object for state management can create load on server causing performance
degradation
Application object:
Application object is used to store data which is visible across entire application and sharedacross multiple user sessions. Data which needs to be persisted for entire life of applicationshould be stored in application object.
In classic ASP, application object is used to store connection strings. It's a great place tostore data which changes infrequently. We should write to application variable only in
application_Onstart event (global.asax) or application.lock event to avoid data conflicts.Below code sample gives idea
Application.Lock();Application["mydata"]="mydata";Application.UnLock();
Session object:
Session object is used to store state specific information per client basis. It is specific toparticular user. Session data persists for the duration of user session you can store session'sdata on web server in different ways. Session state can be configured using the section in the application's web.config file.
Configuration information:
-
8/7/2019 RECENT FAQ'S
35/76
Mode:
This setting supports three options. They are InProc, SQLServer, and State Server
Cookie less:
This setting takes a Boolean value of either true or false to indicate whether the Session is a
cookie less one.
Timeout:
This indicates the Session timeout vale in minutes. This is the duration for which a user'ssession is active. Note that the session timeout is a sliding value; Default session timeoutvalue is 20 minutes
SqlConnectionString:
This identifies the database connection string that names the database used for modeSQLServer.
Server:
In the out-of-process mode State Server, it names the server that is running the requiredWindows NT service: aspnet_state.Port:
This identifies the port number that corresponds to the server setting for mode StateServer. Note that a port is an unsigned integer that uniquely identifies a process runningover a network.
You can disable session for a page using EnableSessionState attribute. You can set off
session for entire application by setting mode=off in web.config file to reduce overhead forthe entire application.
Session state in ASP.NET can be configured in different ways based on various parametersincluding scalability, maintainability and availability
In process mode (in-memory)- State information is stored in memory of web server
Out-of-process mode- session state is held in a process called aspnet_state.exe thatruns as a windows service.
Database mode session state is maintained on a SQL Server database.
In process mode:
This mode is useful for small applications which can be hosted on a single server. Thismodel is most common and default method to store session specific information. Sessiondata is stored in memory of local web server
Configuration information:
Advantages:
Fastest mode
Simple configuration
-
8/7/2019 RECENT FAQ'S
36/76
Disadvantages:
Session data will be lost if the worker process or application domain recycles
Not ideal for web gardens and web farms
Out-of-process Session mode (state server mode):
This mode is ideal for scalable and highly available applications. Session state is held in aprocess called aspnet_state.exe that runs as a windows service which listens on TCP port42424 by default. You can invoke state service using services MMC snap-in or by runningfollowing net command from command line.
Net start aspnet_state
Configuration information:
Advantages: Supports web farm and web garden configuration
Session data is persisted across application domain recycles. This is achieved byusing separate worker process for maintaining state
Disadvantages:
Out-of-process mode provides slower access compared to In process
Requires serializing data
SQL-Backed Session state:
ASP.NET sessions can also be stored in a SQL Server database. Storing sessions in SQLServer offers resilience that can serve sessions to a large web farm that persists across IIS
restarts.
SQL based Session state is configured with aspnet_regsql.exe. This utility is located in .NETFramework's installed directoryC:\\microsoft.net\framework\. Running this utility will create a
database which will manage the session state.
Configuration Information:
Advantages:
Supports web farm and web garden configuration
Session state is persisted across application domain recycles and even IIS restartswhen session is maintained on different server.
Disadvantages:
Requires serialization of objects
Choosing between client side and Server side management techniques is driven by variousfactors including available server resources, scalability and performance. We have to
-
8/7/2019 RECENT FAQ'S
37/76
leverage both client side and server side state management options to build scalableapplications.
When leveraging client side state options, ensure that little amount of insignificantinformation is exchanged between page requests.
Various parameters should be evaluated when leveraging server side state options including
size of application, reliability and robustness. Smaller the application, In process is thebetter choice. We should account in the overheads involved in serializing and deserializingobjects when using State Server and Database based session state. Application state shouldbe used religiously.
ASP.NET Session state provides a place to store values that will persist across page requests. Values stored
in Session are stored on the server and will remain in memory until they are explicitly removed or until the
Session expires.
Storing and retrieving a value in the Session is as simple as:
VB
Session("Name") = "John Doe"'orSession.Add("Name","John Doe")'retrieving
Dim Name As String = Session("Name")
C#
Session["Name"] = "John Doe";//orSession.Add("Name","John Doe");//retrievingstring
Name = (string)Session["Name"];
By default the Session will be created within the same process that your web site runs in (InProc). This is
controlled by a setting in the web.config file:
Although running the Session In Process is very convenient, it does mean that all Session values will be lost
whenever the application recycles (such as when deploying updates) . There are alternate modes you can
use that will allow the Session state to survive even when the application recycles. The available options
are:
Off - No session state will be stored
InProc - (The Default) Session state exists within the process the web is using
StateServer - Session data is sent to the configured stateserver service
SQLServer - Session data is store in the configured sql server database
Both the StateServer mode and the SQLServer mode allow Session state to survive an application recycle.
But, when storing reference type objects (such as class instances), they can only be stored to StateServer
or SQLServer if they have been marked with the Serializable attribute.
An important consideration for using Session state is that the Session does expire. By default, if a user does
not access their Session data within 20 minutes (by default), the Session will expire and all items that had
been stored in the Session will be discarded. Because of this, it is important to check the object that
is returned from the Session to see if it exists or if it is null before you try to work with it. For example:
object sessionObject = Session["someObject"];
if (sessionObject != null) {
myLabel.Text = sessionObject.ToString();
}
The Session Timeout is adjustable through a web.config setting but increasing the timeout value can put
memory pressure on your server that may be undesirable.
http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspxhttp://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx -
8/7/2019 RECENT FAQ'S
38/76
Other commonly used Session methods are:
Session.Abandon() - removes the Session and all items that it contains
Session.Clear() - removes all items from the Session
Session.RemoveAll() - removes all items from the Session
Session.Remove("itemName") - removes the item that was stored under the name "itemName"
7,353,985 members and growing! (22,713 online)
Top of Form
MenuBarForm
Email Password
Sign in
Remember me?
Lost password?
Bottom of Form
Home
Articles
Chapters and Sections
Search
Latest Articles
Latest Tips/Tricks
Top Articles
Beginner Articles
Technical Blogs
Post an Article
Post Tip & Trick
Post your BlogPosting/Update
Guidelines
Article Competition
Questions & Answers
Ask a Question about this
article
Quick Answers
Top of Form
Search
Search within:
Articles
Quick
Answers
Messages
Jobs
Product
CatalogBottom of Form
http://www.codeproject.com/script/Membership/SendPassword.aspx?rp=/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/http://www.codeproject.com/script/Articles/Latest.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/info/search.aspxhttp://www.codeproject.com/script/Articles/Latest.aspxhttp://www.codeproject.com/script/Articles/Latest.aspx?at=6http://www.codeproject.com/script/Articles/TopArticles.aspx?ta_so=4http://www.codeproject.com/info/search.aspx?aidlst=152&sa_us=Truehttp://www.codeproject.com/script/Articles/BlogArticleList.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/Tips/post.aspxhttp://www.codeproject.com/script/Articles/BlogFeed.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1http://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/http://www.codeproject.com/KB/aspnet/ExploringSession.aspx#Mainhttp://www.codeproject.com/script/Membership/SendPassword.aspx?rp=/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/http://www.codeproject.com/script/Articles/Latest.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/info/search.aspxhttp://www.codeproject.com/script/Articles/Latest.aspxhttp://www.codeproject.com/script/Articles/Latest.aspx?at=6http://www.codeproject.com/script/Articles/TopArticles.aspx?ta_so=4http://www.codeproject.com/info/search.aspx?aidlst=152&sa_us=Truehttp://www.codeproject.com/script/Articles/BlogArticleList.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/Tips/post.aspxhttp://www.codeproject.com/script/Articles/BlogFeed.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1http://www.codeproject.com/script/Answers/List.aspx?tab=active -
8/7/2019 RECENT FAQ'S
39/76
Ask a Question
View Unanswered
Questions
View All Questions...
C# questions
ASP.NET questionsVB.NET questions
C++ questions
C#3.0 questions
Programming Discussions
All Message Boards...
Application Lifecycle>
Design and Architecture
Running a Business
Sales / Marketing
Collaboration / Beta
Testing
Work & Training Issues
C / C++ / MFC>
ATL / WTL / STL
Managed C++/CLI
C#
Database
IT & Infrastructure>
Hardware & Devices
System Admin
Java.NET Framework
Mobile
Sharepoint
Silverlight / WPF
Visual Basic
Web Development>
ASP.NET
CSS
Javascript
PHPSite Bugs / Suggestions
Other Languages>
General Indian Topics
General Chinese Topics
Learning Zones
The Commerce Zone
The Mobile Zone
http://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/script/Answers/List.aspx?tab=unansweredhttp://www.codeproject.com/script/Answers/List.aspx?tab=unansweredhttp://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=81http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=85http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=842http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=78http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=69http://www.codeproject.com/script/Forums/List.aspxhttp://www.codeproject.com/Forums/1580997/Application-Lifecycle.aspxhttp://www.codeproject.com/Forums/369270/Design-and-Architecture.aspxhttp://www.codeproject.com/Forums/1533717/Running-a-Business.aspxhttp://www.codeproject.com/Forums/1533716/Sales-Marketing.aspxhttp://www.codeproject.com/Forums/1651/Collaboration-Beta-Testing.aspxhttp://www.codeproject.com/Forums/1651/Collaboration-Beta-Testing.aspxhttp://www.codeproject.com/Forums/3304/Work-Training-Issues.aspxhttp://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspxhttp://www.codeproject.com/Forums/4486/ATL-WTL-STL.aspxhttp://www.codeproject.com/Forums/3785/Managed-Cplusplus-CLI.aspxhttp://www.codeproject.com/Forums/1649/Csharp.aspxhttp://www.codeproject.com/Forums/1725/Database.aspxhttp://www.codeproject.com/Forums/1642/IT-Infrastructure.aspxhttp://www.codeproject.com/Forums/186301/Hardware-Devices.aspxhttp://www.codeproject.com/Forums/1644/System-Admin.aspxhttp://www.codeproject.com/Forums/1643/Java.aspxhttp://www.codeproject.com/Forums/1650/NET-Framework.aspxhttp://www.codeproject.com/Forums/13695/Mobile.aspxhttp://www.codeproject.com/Forums/1540733/Sharepoint.aspxhttp://www.codeproject.com/Forums/1004257/Silverlight-WPF.aspxhttp://www.codeproject.com/Forums/1646/Visual-Basic.aspxhttp://www.codeproject.com/Forums/1640/Web-Development.aspxhttp://www.codeproject.com/Forums/12076/ASP-NET.aspxhttp://www.codeproject.com/Forums/1580227/CSS.aspxhttp://www.codeproject.com/Forums/1580226/Javascript.aspxhttp://www.codeproject.com/Forums/1213656/PHP.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/Forums/1580229/Hindi.aspxhttp://www.codeproject.com/Forums/1580230/Chinese.aspxhttp://www.codeproject.com/Zones/index.aspxhttp://www.codeproject.com/Zones/Commerce/http://www.codeproject.com/Zones/Mobile/http://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/script/Answers/List.aspx?tab=unansweredhttp://www.codeproject.com/script/Answers/List.aspx?tab=unansweredhttp://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=81http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=85http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=842http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=78http://www.codeproject.com/script/Answers/List.aspx?tab=active&tags=69http://www.codeproject.com/script/Forums/List.aspxhttp://www.codeproject.com/Forums/1580997/Application-Lifecycle.aspxhttp://www.codeproject.com/Forums/369270/Design-and-Architecture.aspxhttp://www.codeproject.com/Forums/1533717/Running-a-Business.aspxhttp://www.codeproject.com/Forums/1533716/Sales-Marketing.aspxhttp://www.codeproject.com/Forums/1651/Collaboration-Beta-Testing.aspxhttp://www.codeproject.com/Forums/1651/Collaboration-Beta-Testing.aspxhttp://www.codeproject.com/Forums/3304/Work-Training-Issues.aspxhttp://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspxhttp://www.codeproject.com/Forums/4486/ATL-WTL-STL.aspxhttp://www.codeproject.com/Forums/3785/Managed-Cplusplus-CLI.aspxhttp://www.codeproject.com/Forums/1649/Csharp.aspxhttp://www.codeproject.com/Forums/1725/Database.aspxhttp://www.codeproject.com/Forums/1642/IT-Infrastructure.aspxhttp://www.codeproject.com/Forums/186301/Hardware-Devices.aspxhttp://www.codeproject.com/Forums/1644/System-Admin.aspxhttp://www.codeproject.com/Forums/1643/Java.aspxhttp://www.codeproject.com/Forums/1650/NET-Framework.aspxhttp://www.codeproject.com/Forums/13695/Mobile.aspxhttp://www.codeproject.com/Forums/1540733/Sharepoint.aspxhttp://www.codeproject.com/Forums/1004257/Silverlight-WPF.aspxhttp://www.codeproject.com/Forums/1646/Visual-Basic.aspxhttp://www.codeproject.com/Forums/1640/Web-Development.aspxhttp://www.codeproject.com/Forums/12076/ASP-NET.aspxhttp://www.codeproject.com/Forums/1580227/CSS.aspxhttp://www.codeproject.com/Forums/1580226/Javascript.aspxhttp://www.codeproject.com/Forums/1213656/PHP.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/Forums/1580229/Hindi.aspxhttp://www.codeproject.com/Forums/1580230/Chinese.aspxhttp://www.codeproject.com/Zones/index.aspxhttp://www.codeproject.com/Zones/Commerce/http://www.codeproject.com/Zones/Mobile/ -
8/7/2019 RECENT FAQ'S
40/76
The Cloud Zone
The Hardware Zone
The Parallelism Zone
The SQL Zone
WhitePapers / Webcasts
JobsLatest
Search
Post a Job
FAQ and Pricing
Features
Who's Who
CodeProject MVPs
Company Listings
Component & Service
Catalog
Competitions
News
Newsletter archive
Press Releases
Surveys
CodeProject Stuff
CodeProject VS Addin
Help!
What is 'The Code
Project'?
General FAQPost a Question
Bugs and Suggestions
Site Directory
Advertise with us
About Us
The Lounge The
Soapbox
4.76 / 5, 275votes
1 2 3 4 5
http://www.codeproject.com/Zones/Cloud/http://www.codeproject.com/Zones/Hardware/http://www.codeproject.com/Zones/Parallelism/http://www.codeproject.com/Zones/SqlServer/http://www.codeproject.com/Zones/WhitePapers/http://www.codeproject.com/script/Jobs/List.aspxhttp://www.codeproject.com/script/Jobs/List.aspxhttp://www.codeproject.com/script/Jobs/Search.aspxhttp://www.codeproject.com/script/Jobs/Edit.aspxhttp://www.codeproject.com/KB/FAQs/JobBoardFAQ.aspxhttp://www.codeproject.com/script/Membership/Profiles.aspxhttp://www.codeproject.com/script/Awards/MVPWinners.aspxhttp://www.codeproject.com/script/Membership/Profiles.aspx?mgtid=1&mgm=Truehttp://www.codeproject.com/script/Catalog/List.aspxhttp://www.codeproject.com/script/Catalog/List.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1&awsac=truehttp://www.codeproject.com/script/News/List.aspxhttp://www.codeproject.com/script/Mailouts/Archive.aspx?mtpid=1http://www.codeproject.com/script/PressReleases/Preview.aspxhttp://www.codeproject.com/script/Surveys/List.aspxhttp://www.codeproject.com/Info/Stuff.aspxhttp://www.codeproject.com/Services/Addins/http://www.codeproject.com/KB/FAQs/http://www.codeproject.com/info/guide.aspxhttp://www.codeproject.com/info/guide.aspxhttp://www.codeproject.com/KB/FAQs/http://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/info/MediaKit.aspxhttp://www.codeproject.com/info/about.aspxhttp://www.codeproject.com/Lounge.aspxhttp://tmp/svfin.tmp/javascript:void();http://tmp/svfin.tmp/javascript:void();http://www.codeproject.com/Zones/Cloud/http://www.codeproject.com/Zones/Hardware/http://www.codeproject.com/Zones/Parallelism/http://www.codeproject.com/Zones/SqlServer/http://www.codeproject.com/Zones/WhitePapers/http://www.codeproject.com/script/Jobs/List.aspxhttp://www.codeproject.com/script/Jobs/List.aspxhttp://www.codeproject.com/script/Jobs/Search.aspxhttp://www.codeproject.com/script/Jobs/Edit.aspxhttp://www.codeproject.com/KB/FAQs/JobBoardFAQ.aspxhttp://www.codeproject.com/script/Membership/Profiles.aspxhttp://www.codeproject.com/script/Awards/MVPWinners.aspxhttp://www.codeproject.com/script/Membership/Profiles.aspx?mgtid=1&mgm=Truehttp://www.codeproject.com/script/Catalog/List.aspxhttp://www.codeproject.com/script/Catalog/List.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1&awsac=truehttp://www.codeproject.com/script/News/List.aspxhttp://www.codeproject.com/script/Mailouts/Archive.aspx?mtpid=1http://www.codeproject.com/script/PressReleases/Preview.aspxhttp://www.codeproject.com/script/Surveys/List.aspxhttp://www.codeproject.com/Info/Stuff.aspxhttp://www.codeproject.com/Services/Addins/http://www.codeproject.com/KB/FAQs/http://www.codeproject.com/info/guide.aspxhttp://www.codeproject.com/info/guide.aspxhttp://www.codeproject.com/KB/FAQs/http://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/info/MediaKit.aspxhttp://www.codeproject.com/info/about.aspxhttp://www.codeproject.com/Lounge.aspxhttp://tmp/svfin.tmp/javascript:void();http://tmp/svfin.tmp/javascript:void(); -
8/7/2019 RECENT FAQ'S
41/76
Print Article
Twitter
Digg
Facebook
Del.icio.us
Reddit
Stumbleupon
Newsvine
Technorati
Mr. Wong
Yahoo!
Google
Windows Live
Send as Email
Add to your CodeProject bookmarks
Discuss this article
204
Report this article as inappropriate
Article Browse Code Stats Revisions (25)
First Posted 15 Jan 2009
Views 252,603
Bookmarked 498 times
http://www.codeproject.com/KB/aspnet/ExploringSession.aspx?display=Printhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/script/Articles/Report.aspx?aid=32545http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=32545http://www.codeproject.com/script/Articles/Statistics.aspx?aid=32545http://www.codeproject.com/script/Articles/ListVersions.aspx?aid=32545http://www.codeproject.com/script/Articles/Report.aspx?aid=32545http://www.codeproject.com/KB/aspnet/ExploringSession.aspx#_commentshttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspx?display=Printhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspx?display=Printhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/script/Articles/Report.aspx?aid=32545http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=32545http://www.codeproject.com/script/Articles/Statistics.aspx?aid=32545http://www.codeproject.com/script/Articles/ListVersions.aspx?aid=32545 -
8/7/2019 RECENT FAQ'S
42/76
Licence CPOL
C#1.0, C#2.0, C#3.0, C#, ASP.NET, Windows,
Architect, Dev ...
Web Development ASP.NET General
Exploring Session in ASP.Net
By Abhijit Jana | 23 Jan 2009 | Unedited contribution This article describe about session in ASP.Net 2.0 .
Different Types of Session , There Configuration . Also
describe Session on Web Farm , Load balancer , web
garden etc.
Prize winner in Competition "Best ASP.NET article of
January 2009" Top of Form
/w EPDwUKMTAy
Download Session_SampleApplication.zip - 2.85 KB Table of Content
Introduction
What is Session ?
Advantages and Disadvantages of Session.
Storing and Retrieving values from Session
Session ID
Session Mode and State Provider
Session State
Session Event
Session Mode
InProc Session Mode
Overview of InProc Session Mode
When should we use InProc Session Mode ?
Advantages and Disadvantages
StateServer Session Mode
Overview of StateServer Session Mode
Configuration for State Server Session Mode
http://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/info/search.aspx?aidlst=64http://www.codeproject.com/info/search.aspx?aidlst=65http://www.codeproject.com/info/search.aspx?aidlst=69http://www.codeproject.com/info/search.aspx?aidlst=81http://www.codeproject.com/info/search.aspx?aidlst=85http://www.codeproject.com/info/search.aspx?aidlst=94http://www.codeproject.com/info/search.aspx?aidlst=116http://www.codeproject.com/info/search.aspx?aidlst=118http://www.codeproject.com/Chapters/2/Web-Development.aspxhttp://www.codeproject.com/KB/aspnet/http://www.codeproject.com/script/Membership/View.aspx?mid=3978578http://www.codeproject.com/script/Articles/Unedited.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession/Session_SampleApplication.ziphttp://www.codeproject.com/KB/aspnet/ExploringSession.aspx?PageFlow=Fluidhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspx?PageFlow=FixedWidthhttp://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/info/search.aspx?aidlst=64http://www.codeproject.com/info/search.aspx?aidlst=65http://www.codeproject.com/info/search.aspx?aidlst=69http://www.codeproject.com/info/search.aspx?aidlst=81http://www.codeproject.com/info/search.aspx?aidlst=85http://www.codeproject.com/info/search.aspx?aidlst=94http://www.codeproject.com/info/search.aspx?aidlst=116http://www.codeproject.com/info/search.aspx?aidlst=118http://www.codeproject.com/Chapters/2/Web-Development.aspxhttp://www.codeproject.com/KB/aspnet/http://www.codeproject.com/script/Membership/View.aspx?mid=3978578http://www.codeproject.com/script/Articles/Unedited.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession/Session_SampleApplication.zip -
8/7/2019 RECENT FAQ'S
43/76
How StateServer Session Mode Works?
Example Of StateServer Session Mode
Advantages and Disadvantages.
SQL Server Session Mode
How SQL Server Session Mode Works?
When should we use SQL Server Session Mode ? Configuration for SQL Server Session Mode
Advantages and Disadvantages.
Custom Session Mode
How custom session mode works?
When should we use custom session mode ?
Configuration for custom session mode
Advantages and disadvantages
Overview of Production Deployment
Application Pool
Identity of Application Pool
Creating and Assign of Application Pool
Web Garden
How to create web garden
How Session Depends on Web Garden
Web Farm and Load Balancer
Handling Session in Web Farm and Load Balancer
Scenarios
Session And Cookies
What is Cookie-Munging?
How Cookie-Munging Works in ASP.Net ?
Removing Session From Session Variable Enabling and Disabling Session
Summary
Introduction
First of all I would like to thank all the readers who read
and vote for my article. In Beginner's Guide series, I have
written some articles on state management. Probably this
is my last article on state management. Now coming back
to the topic of this article "Exploring Session in ASP.Net" .
This article will give you a very good understanding of
session. In this article I have covered basic of session,different types of storing session object, Session behavior
in web farm scenarios , Session on Load Balancer etc. I
have also explained details of Session Behavior in a Live
production environment. Hope you will enjoy this article
and provide your valuable suggestion and feedback.
What is Session ?
-
8/7/2019 RECENT FAQ'S
44/76
Web is Stateless, which means a new instance of the web
page class is re-created each time the page is posted to
the server. As we all know HTTP is a stateless protocol, it
can't hold the client information on page. If user inserts
some information, and move to the next page, that data
will be lost and user would not able to retrieve theinformation. So what we need? we need to store
information. Session provides that facility to store
information on server memory. It can support any type of
object to store along with our custom object. For every
client Session data store separately, means session data
is stored as per client basis. Have a look at the following
diagram.
Fig : For every client session data store separately State Management using session is one of the asp.net
best features, because it is secure, transparent from users
and we can store any kind of object with in it. Along with
advantages, some times session can causes performance
issue for heavy traffic sites because its stored on server
memory and clients read data from the server itself. Now
lets have a look at the advantages and disadvantages of
using session in our web application.
Advantages and Disadvantages of Session ?
Following are the basic advantages and disadvantages of
using session. I have describe in details with each type of
session at later point of time.
Advantages :
It helps to maintain user states and data to all over the
application.
It can easily be implemented and we can store any kind of
object.
-
8/7/2019 RECENT FAQ'S
45/76
Stores every client data separately.
Session is secure and transparent from user.
Disadvantages :
Performance overhead in case of large volume of user,
because of session data stored in server memory.
Overhead involved in serializing and De-Serializingsession Data. because In case of StateServer and
SQLServer session mode we need to serialize the object
before store.
Besides these, there are many advantages and
disadvantages of session that are based of session Types.
I have Discussed all of them.
Storing and Retrieving values from Session
Storing and Retrieving values in session are quite similar
with ViewState. We can interact with Session State with
System.Web.SessionState.HttpSessionState class,
because this provides built in Session Object with Asp.Net
Pages.
Following code is used for storing a value to session
Collapse | Copy Code
//Storing UserName in Session
Session["UserName"] = txtUser.Text;
Now, let see how we can retrieve values from Session
Collapse | Copy Code
//Check weather session variable null or not
if (Session["UserName"] != null) {
//Retrieving UserName from Session
lblWelcome.Text = "Welcome : " +
Session["UserName"];
}
else
{
//Do Something else
}
we can also store some other object in Session. FollowingExample shows how to store a DataSet in session.
Collapse | Copy Code
//Storing dataset on Session
Session["DataSet"] = _objDataSet;
and following code shows how we can retrieve that
dataset from the session
http://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspx -
8/7/2019 RECENT FAQ'S
46/76
Collapse | Copy Code
//Check weather session variable null or not
if (Session["DataSet"] != null)
{
//Retrieving UserName from Session
DataSet _MyDs = (DataSet)Session["DataSet"];
}
else
{
//Do Something else
}
Ref & for more Information: Read Session Variable Section
Session ID
Asp.Net use 120 bit identifier to track each session. This is
secure enough and can't be reverse engineered. When
client communicate with server, only session id istransmitted, between them. When client request for data,
ASP.NET looks on to session ID and retrieves
corresponding data. This is done in following steps,
Client hits web site and some information is stored in
session.
Server creates a unique session ID for that clients and
stored in Session State Provider .
Again client request For some information with that
unique session ID from Server.
Server,looks on Session Providers, and retrieve theserialized data from state server and type cast the object
.
Just have a look on the pictorial flow,
Fig : Communication of Client, web server, and State
Provider
http://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspx -
8/7/2019 RECENT FAQ'S
47/76
Ref. & for more Information: SessionID in MSDN
Session Mode and State Provider
In ASP.NET there are following session mode available,
InProc
StateServer
SQLServer Custom
For every session State, there is Session Provider.
Following diagram will show you how they are related.
Fig : Session State Architecture
we can choose the session State Provider based on which
session state we are selecting. When ASP.NET request for
any information based on session ID, session state and its
corresponding provider are responsible for sending the
proper information based on user. Following tables show,
the session mode along with there provider Name.
Session
StateMode
State Provider
InProcIn-Memory
Object
StateServe
r
Aspnet_state.
exe
SQLServer DataBase
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspxhttp://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspx -
8/7/2019 RECENT FAQ'S
48/76
CustomCustomProvid
er
apart from that, there is another mode, "Off". If we select
this option the session will be disabled for the application.
But our objective is to use session, so we will look into
that four session State Mode. Ref. & for more Information: Session State Providers
Session States
If we consider about session state, It means all the
settings that you have made for your web application for
maintaining the session. Session State, it self is a big
thing, It says all about your session configuration, Either
in web.config or from code behind. In web.config,
elements used for setting the
configuration of session. Some of them are Mode,
Timeout, StateConnectionString, Custom provider etc. Ihave discussed about each and ever section of connection
string. Before I discussed Session Mode, just take a brief
overview of Session Event
Session Event
There are two types of session events available in
asp.net
Session_Start
Session_End
you can handle both this event in global.asax file of
your web application. When a new session initiate
session_start event raised and Session_End event raisedwhen a session is abandoned or expired.
Collapse | Copy Code
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{ // Code that runs when a session ends.
}
Ref. and for more Information : Application and Session
Events
Session Mode
http://www.codeproject.com/KB/aspnet/Session%20State%20Providershttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06_application_and_session_events.mspx?mfr=truehttp://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06_application_and_session_events.mspx?mfr=truehttp://www.codeproject.com/KB/aspnet/Session%20State%20Providershttp://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06_application_and_session_events.mspx?mfr=truehttp://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06_application_and_session_events.mspx?mfr=true -
8/7/2019 RECENT FAQ'S
49/76
I have already discussed about the session mode in
ASP.NET, Following are the different types of session
modes available in ASP.Net.
Off
InProc
StateServer SQLServer
Custom
If we set Session Mode="off" in web.config, Session will
be disabled to all over the application. For this we need to
configure web.config in following way
InPorc Session Mode :
This is the default session mode in Asp.Net. Its stores
session Information in Current Application Domain. This is
the best session mode which is based on web application
Performance. But main disadvantage is that, It will lose
the data if we restart the server. There are some more
advantages and disadvantages of InProc session mode. I
will come to those points again . Overview of InProc Session Mode :
As I have already discussed InProc mode session data will
be stored on the current application domain. So It is easily
and quickly available.
-
8/7/2019 RECENT FAQ'S
50/76
So, InProc session mode store its session data in a
memory object on that application domain. This ishandled by worker process in application pool. So If we
restart the server we will lose the session data. If Client
request for the data , state provide read the data from In-
Memory Object and return it to the client. In web.config
we have to mention Session mode and also we have to
set the Timeout.
This Session TimeOut Setting keeps session alive for 30
minute. This can be configurable from Code behind too.
Collapse | Copy Code
Session.TimeOut=30;
There are two type of session events available in asp.net
Session_Start() and Session_End. It is the only mode that
supports the Session_End() event. These events will call
after the session timeout period is over. The general flow
for the InProc Session State is some thing like this.
http://www.codeproject.com/KB/aspnet/ExploringSession.aspxhttp://www.codeproject.com/KB/aspnet/ExploringSession.aspx -
8/7/2019 RECENT FAQ'S
51/76
Now, when the Session_End() will call that depends on
Session Time Out. This is a very fast mechanism because
no serialization occurs for storing and retrieving data, and
data are staying inside the same application domain.
When Should we use InProc Session Mode ?
InProc is the default session mode. It can be very helpful
for a small web sites and where the number of user are
very less, We should avoid InProc in case of Web Garden
(I will come to this topic in details) Scenario .
Advantages and Disadvantages
Advantages :
It store Session data in memory object of current
application domain. So accessing data is very fast and
data is easily available.
There is not requirements of serialization to store data in
InProc Session Mode.
Implementation is very easy, just similar to using View
State.
Disadvantages :
although InProc Session is fastest, common and defaultmechanism, It has lots of limitation.
If the worker Process or application domain recycles all
session data will be lost.
Though its fastest, but more session data and more users
can affects performance, because of memory.
we can't use it in web Garden scenarios .
-
8/7/2019 RECENT FAQ'S
52/76
This session mode is not suitable for web farm scenarios
also.
So as per above discussion, we can conclude InProc is
very fast session storing mechanism but suitable for small
web application. InProc Session Data will get lost if we
Restart the server, application domain recycles It is alsonot suitable for Web Farm and Web Garden Scenarios.
Now have a look that what are the other option available
to overcome these problem. First Come to StateServer
Mode.
StateServer Session