Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

What is Clean code?

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ~Martin Fowler


There are many explanations and definitions about clean code but according to me clean code is:

1. Easy to understand.
2. Easy to modify.
3. No redundant (Duplicate code) code.
4. Easy to test.
5. Works correctly

Asp.net state management interview questions and Answers part 4

Asp.net state management interview questions and Answers part 4

31.  How to store and retrieve values from session?

Its quite simple and similar to view state in asp.net. We can interact with session state with the System.Web.SessionState.HttpSessionState class, because this provides the built-in session object in ASP.NET pages.

 //Storing UserName in Session
  Session["UserFullName"] =txtFullName.Text;

 

32.  What are advantages and Limitation of using Hidden fields ?

Advantages:

 1.  They are simple to implement.
 2.  As data is cached on client side they work with Web Farms.
 3. All browsers support hidden field.
4.  No server resources are required.

Disadvantages:

1. They can be tampered creating a security hole.
2. Page performance decreases if you store large data, as the data are stored in
pages itself.
3. `Hidden fields do not support rich structures as HTML hidden fields are only
single valued. Then you have to work around with delimiters etc to handle
complex structures.
4. Below is how you will actually implement hidden field in a project
<asp:HiddenField ID="hiddenUserid" runat="server" />

 

33.  Does the performance for viewstate vary according to User controls?

Performance of viewstate varies depending on the type of server control to which it is
applied. Label, TextBox, CheckBox, RadioButton, and HyperLink are server controls
that perform well with ViewState. DropDownList, ListBox, DataGrid, and DataList suffer
from poor performance because of their size and the large amounts of data making
roundtrips to the server.

 

34.  What are advantages and disadvantages of using Cookies?

Advantages:

1.  No server resources are required as they are stored in client.
2. They are light weight and simple to use

Disadvantages:

1.  Most browsers place a 4096-byte limit on the size of a cookie, although support  for 8192-byte cookies is becoming more common in the new browser and client-device versions available today.
2.  Some users disable their browser or client device’s ability to receive cookies,
There by limiting the use of cookies.
3.  Cookies can be tampered and thus creating a security hole.
4.  Cookies can expire thus leading to inconsistency.
5.  Below is sample code of implementing cookies
Request.Cookies.Add(New HttpCookie(“name”, “usrname”))

 

35. Benefits and limitations of using Query Strings?

A query string is information sent to the server appended to the end of a page URL.

Advantages:

1. No server resources are required.
2. The query string containing in the HTTP requests for a specific URL.
3. All browsers support query strings.

Disadvantages:

1. Query string data is directly visible to user thus leading to security problems.-
Most browsers and client devices impose a 255-character limit on URL length.
2. Below is a sample “name” and “lastName” query string passed in URL http://www.localhost.com/Address.aspx?name=nagnath &lastName=kendre . This query string data can then be requested later by using
Request.QueryString(“name”).

 

36. How do we access viewState value of this page in the next page?

View state is page specific; it contains information about controls embedded on the particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name, __POSTBACK . This field is embedded only when there is an IButtonControl on thepage and its PostBackUrl property is set to a non-null value. 

This field contains the view state information of the poster page. To access the view state of the poster page, you can use the new PreviousPage property of the page:

Page poster = this.PreviousPage;
Then you can find any control from the previous page and read its state:
Label posterLabel = poster.findControl("myLabel");
string lbl = posterLabel.Text;
This cross-page post back feature also solves the problem of posting a Form to multiple
pages, because each control, in theory, can point to different post back URL.

 

37. Can we post and access view state in another application?

 You can post back to any page and pages in another application, too. But if you are posting pages to another application, the PreviousPage property will return null.

This is a significant restriction, as it means that if you want to use the view state, you are confined, for example, posting to pages in the same virtual directory. Even so, this is a highly acceptable addition to the functionality of ASP.NET.

 

38. What does the "EnableViewState" property do? Why would I want it on or off?

It allows the page to save the users input on a form across postbacks.
It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.

 


Asp.net state management interview questions and Answers part 3

Asp.net state management interview questions and Answers part 3


21.  Which mode is better, InProc or SQL Server, for Session State mode in asp.net?

IT depends on application hosting and requirement I will explain in short advantages and disadvantages of both.

InProc: 

InProc session is much much faster, has less requirements (serialization), but unusable when you're running your application on several web servers;
Reliability is first problem when using InProc. When using InProc mode, all sessions are lost whenever web application restarts.

SQL Server: 

Sql session is much slower, has object serialization requirements, but can be shared between several web servers;

22.  What are advantages and disadvantages using InProc session sate?

Advantages:

1.  InProc is default session state configuration not required for State server and sql server external configuration required.
2.  You can save any object in session variable even if it is not serializable. For State and SQl server requires objects to be serializable.
3.  InProc mode works on shared web hosting. State Server is usually not allowed, and some shared web hosting providers give option to use SQL Server. In the other hand, InProc works in any hosting package.

Disadvantages:

1.  Reliability is first problem when using InProc. When using InProc mode, all sessions are lost whenever web application restarts.
2.   Scalability is one more problem when using InProc mode. Each user has its own collection of session variables. On high traffic websites, with thousands of visitors online, sesssion data easily grow and spend complete memory on web server.
3. There is a problem on web farms and web gardens. If you host website on web farm (multiple servers) or web garden (multiple processors) ASP.NET application will use multiple processes. Since InProc stores session data inside single process, session data will be lost when visitor request goes to different server or processor.

 

23.  What are the advantages and disadvantages of Out-Proc (StateServer) Session mode?

Advantages:

It keeps data separate from IIS so any issues with IIS will not hamper session data
It is useful in web farm and web garden scenarios.

Disadvantages:

Process is slow due to serialization and de-serialization.
State Server always needs to be up and running.

24 What are Advantages and disadvantages using SQL server session state?

Advantages:

1.  If IIS restart session data not affected /application not affected with inProc session we face this issue frequently.
2.  More Secure and reliable compared with InProc and state server.
3.  Usefull in Web farm and Web gardens scenarios.

Disadvantages:

1.  Performance issue is main disadvantage (processing is slow), with SQL server session state application is slow compared with InProc.
2.  Object serialization and de serialization requires crates overhead and network traffic issue.
3.  External configuration required for sql server session state.

25  Where data stored with SQL server session mode?

This is beginner level question, answer is sterilized session data stored in sql server database.

26  Session_End() event is supported by which mode?

Session_End() event is supported by InProc session mode only.

27.   What are advantages and disadvantages using view state?

 Advantages:

1.  No server resources required
2. simple implementation
3. automatic retention of page and control state
4 . Enhanced security features. The values in view state are hashed, compressed, and encoded for Unicode implementations.

Disadvantages:

1.  Performance. The view state is stored in the page itself, so increase the page size.
2.  Security. The view state is stored in a hidden field on the page. Although view state stores data in a hashed format, it can be tampered with.

28.   What are the advantages and disadvantages of using client side state management?

Advantages:

No server resources are required.
Simple implementation

Disadvantages:

Performance considerations
Potential security risks
Depends on browser compatibility

 

29.   What are Session Events?

There are two types of session events available in ASP.NET:

Session_Start
Session_End

You can handle both these events in the global.asax file of your web application. When a new session initiates, the session_start event is raised, and the Session_End event raised when a session is abandoned or expires.

 

30.   What is session ID?

ASP.NET uses an 120 bit identifier to track each session. This is secure enough and can't be reverse engineered. When a client communicates with a server, only the session ID is transmitted between them. When the client requests for data, ASP.NET looks for the session ID and retrieves the corresponding data.