Wednesday, 25 December 2013

Type of session in Dot net

How many types of Session :-


Priviously we discussed  about Session and session interview question We will talk about types of session.
Types of session

  1. In-process session
  2. Out process session / State server session
  3. Sql server session 
  4. Off session mode 
  5. Custom session mode 

In process Session mode

When the session state mode set to inProc :-The session state variable are stored on the web server memory inside the asp.net worker process.This is default session state mode.
It is very helpful small website or where number of user very less.we should avoid InProc in "web garden".

Web Garden- Web application deployed on a server with multiple processors.
Web Farm- Web application deployed on multiple server.
For detail of "Web garden" and "web farm" click here

  1. Off - Disables session state for entire web application 
  2. Inproc - 
      Fig(1)

      Fig(2)

    Fig(3)
Video for Inproc session mode in Dot Net
 Now the behind the web Form 1(Fig -1) coding will (coding for sending the data from one web  form to another web form)

Protected void btnsenddata_Click( Object sender , Event args e)
{
      Session ["name"] = textbox1.text;
      Session ["Email"] = textbox2.text;
Response.redirect("webform2.aspx");

}

Now the behind the web Form 1(Fig -1)
Protected void Page_Load( Object sender , Event args e)
{    
     if(Session ["name"] ! = null)
{
      lable1.text = Session ["name"].ToString();
}
  
     if(Session ["Email"] ! = null)
 {
     lable2.text = Session ["Email"] .ToString();

}
}

After this we have to set in web Config file
<Configuration>
<system.web>
<sessionState mode = "Inproc" timeout = "20"
</sessionstate>

For More Detail Watch Above video...

Note - If we set session state mode as "Off" then Disables session state for entire web application.



Advantages Disadvantages
Easy to implement, all time it require is, to set, The session state mod=inproc
in web config file.
Session state data is lost when the worker process or application pool is recycled 
It is best because the session state memory rept on the web server with in the Asp.net worker process.Not suitable for webform & webgarden.
Suitable for web application hosted on a single server.,,
Object can be added without serialization.
Scalability could be on an issue. 

Out process/ State server Session mode



  • State server uses a stand alone window services which is independent of IIS and can also be run on separate server.
  • This session state is totally managed by Asp.net-state.exe.
  • This server may run on the same system, But its outside of the main application domain where your web application is running. This means if you restart your application process your session data will be alive.
  • This has many disadvantages due the overhead of the serialization & De-serialization involved. it also increase the cost of the data access because every time the user retrieves session data.  



 Now the behind the web Form 1(Fig -1) coding will (coding for sending the data from one web  form to another web form)

Protected void btnsenddata_Click( Object sender , Event args e)
{
      Session ["name"] = textbox1.text;
      Session ["Email"] = textbox2.text;
Response.redirect("webform2.aspx");

}

Now the behind the web Form 1(Fig -1)
Protected void Page_Load( Object sender , Event args e)
{    
     if(Session ["name"] ! = null)
{
      lable1.text = Session ["name"].ToString();
}
  
     if(Session ["Email"] ! = null)
 {
     lable2.text = Session ["Email"] .ToString();

}
}

After this we have to set in web Config file
<Configuration>
<system.web>
<sessionState mode = "StateServer"  StateconnectionString =" tcpip = localhost = ipaddress"
  timeout = "20"
</sessionstate>

For More Detail Watch Above video...


Sql server session 

When Should be used SQL Server session mode :-
  • SQL Server session mode is a more reliable & secure session state management.
  • It keeps data in a centralized location (database)
  • we should use SQL Server session mode when we need to implement session with more security.
  • If there happens to be frequent server restarts, This is an ideal choice.
  • This is the perfect mode for web form and web garden security.
  • We can use SQL Server session mode when we need to share session  b/w two different application.





Protected void btnsenddata_Click( Object sender , Event args e)
{
      Session ["name"] = textbox1.text;
      Session ["Email"] = textbox2.text;
Response.redirect("webform2.aspx");

}

Now the behind the web Form 1(Fig -1)
Protected void Page_Load( Object sender , Event args e)
{    
     if(Session ["name"] ! = null)
{
      lable1.text = Session ["name"].ToString();
}
  
     if(Session ["Email"] ! = null)
 {
     lable2.text = Session ["Email"] .ToString();

}
}

After this we have to set in web Config file
<Configuration>
<system.web>
<sessionState mode = "SqlServer"  SqlConnectionString =" DataSource = ;integrated security  =SSPI"
  timeout = "20"
</sessionstate>

For More Detail Watch Above video...





C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...