.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> ASP.Net >> Post New Question Subscribe to Interview Questions

Session state vs. View state:

Posted By :shahin     Posted Date :November 22, 2009    Points :10   Category :ASP.Net 
In some cases, using view state is not feasible. The alternative for view state is session state. Session state is employed under the following situations:
o Large amounts of data - View state tends to increase the size of both the HTML page sent to the browser and the size of form posted back. Hence session state is used.
o Secure data - Though the view state data is encoded and may be encrypted, it is better and secure if no sensitive data is sent to the client. Thus, session state is a more secure option.
o Problems in serializing of objects into view state - View state is efficient for a small set of data. Other types like DataSet are slower and can generate a very large view state.

You can also find related Interview Question to Session state vs. View state:  below: 

Session state vs View state

  
In some cases, using view state is not feasible. The alternative for view state is session state. Session state is employed under the following situations:
. Large amounts of data - View state tends to increase the size of both the HTML page sent to the browser and the size of form posted back. Hence session state is used.
. Secure data - Though the view state data is encoded and may be encrypted, it is better and secure if no sensitive data is sent to the client. Thus, session state is a more secure option.
. Problems in serializing of objects into view state - View state is efficient for a small set of data. Other types like DataSet are slower and can generate a very large view state (More...)

Which typically consumes more memory: application state or session state?

  
Session state tends to use much more memory than application state, because copies of all variables are stored for each user. (More...)

Which might not work if a user has disabled cookies in his or her Web browser: application state or session state?

  
Session state, by default, won't work if a Web browser that supports cookies has cookies disabled. Application state isn't user-specific, though, and doesn't need to be tracked in cookies. Therefore, application state works regardless of cookies. (More...)

What is View State Chunking?

  
View state chunking is new in ASP.NET, version 2.0.The ViewState property retains values between multiple requests for the same page. When an ASP.NET page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden field. If the data is too long for a single field (as specified in the MaxPageStateField-Length property), then ASP.NET performs view state chunking to split it across multiple hidden fields. (More...)

Is view state lost if a user refreshes a Web page? What if the user copies the URL and open it in other browser?

  
View state is maintained within a page's HTML, so it is lost if a page is refreshed or if the URL is copied. (More...)

Which typically consumes more memory: application state or session state?

  
Session state tends to use much more memory than application state, because copies of all variables are stored for each user. (More...)

Which might not work if a user has disabled cookies in his or her Web browser: application state or session state?

  
Session state, by default, won't work if a Web browser that supports cookies has cookies disabled. Application state isn't user-specific, though, and doesn't need to be tracked in cookies. Therefore, application state works regardless of cookies (More...)

Can the view state be encrypted?

  
The view state can be encrypted by setting EnableViewStateMac to true and either modifying the element in Machine.config to or by adding the above statement to Web.config. (More...)

What's the maximum size of a view state?

  
Maximum size of a viewstate should not be more than 25-30% of the page size (More...)

How to update and retrieve value from a session state object?

  
To add or update a session state item use the following syntax,
[CODE]Session["Item Name"]= value;[/CODE]
Ex:- [CODE]Session["Name"]= Abhisek;[/CODE]
You can also pass a variable.

To to retrieve a session state items value use following ,
[CODE]String name=Session["Name"].ToString();[/CODE]
You can also retrieve to other formats according the session state item's data. (More...)

What is view state?

  
The web is stateless. But in ASP.NET, the state of a page is maintained in the in the page itself automatically. How? The values are encrypted and saved in hidden controls. this is done automatically by the ASP.NET. This can be switched off / on for a single control (More...)

How to specify session state mode in ASP.NET ?

  
stateConnectionString="tcpip=192.168.100.100:420420"
sqlConnectionString="data source=192.168.100.100; Integrated
Security=SSPI"
cookieless="false"
timeout="20"
/> (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend