Saturday 7 June 2014

What does the "EnableViewState" property do? Why do we want it On or Off?

The EnableViewState property enables the ViewState property on the page. It is set to On to allow the page to save the users input between postback requests of a Web page; that is, between the Request and corresponding Response objects. When this property is set to Off, the page does not store the users input during postback.

To which class a Web form belongs to in the .NET Framework class hierarchy?

A Web form belongs to the System.Web.UI.Page class.

Friday 6 June 2014

What type of code, client-side or server-side, is found in a code-behind file of a Web page?

A code-behind file contains the server-side code, which means that the code contained in a code-behind file is executed at the server.

What is the appSettings Section in the web.config file?

The web.config file sets the configuration for a Web project. The appSettings block in configuration file sets the user-defined values for the whole application.

For example, in the following code snippet, the specified ConnectionString section is used throughout the project for database connection:

<configuration>
<appSettings>
<add key="ConnectionString" value="server=indiabixserver; pwd=dbpassword; database=indiabix" />
</appSettings>
...

How can you dynamically add user controls to a page?

User controls can be dynamically loaded by adding a Web User Control page in the application and adding the control on this page.

Why do we need nested master pages in a Web site?

When we have several hierarchical levels in a Web site, then we use nested master pages in the Web site.

Where should the data validations be performed-at the client side or at the server side and why?

Data validations should be done primarily at the client side and the server-side validation should be avoided because it makes server task overloaded. If the client-side validation is not available, you can use server-side validation. When a user sends a request to the server, the validation controls are invoked to check the user input one by one.

What are the major built-in objects in ASP.NET?

The major built-in objects in ASP.NET are as follows:

  • Application
  • Request
  • Response
  • Server
  • Session
  • Context
  • Trace

What is a round trip?

The trip of a Web page from the client to the server and then back to the client is known as a round trip.

Explain the cookie less session and its working.

ASP.NET manages the session state in the same process that processes the request and does not create a cookie. It is known as a cookie less session. If cookies are not available, a session is tracked by adding a session identifier to the URL. The cookie less session is enabled using the following code snippet: <sessionState cookieless="true" />

What is the difference between adding items into cache through the Add() method and through the Insert() method?

Both methods work in a similar way except that the Cache.Add() function returns an object that represents the item you added in the cache. The Cache.Insert() function can replace an existing item in the cache, which is not possible using the Cache.Add() method.

How can you ensure that no one has tampered with ViewState in a Web page?

To ensure that no one has tampered with ViewState in a Web page, set the EnableViewStateMac property to True.

What do you understand by aggregate dependency?

Aggregate dependency allows multiple dependencies to be aggregated for content that depends on more than one resource. In such type of dependency, you need to depend on the sum of all the defined dependencies to remove a data item from the cache.

What is State Management? How many ways are there to maintain a state in .NET?

State management is used to store information requests. The state management is used to trace the information or data that affect the state of the applications.

There are two ways to maintain a state in .NET, Client-Based state management and Server-Based state management.

The following techniques can be used to implement the Client-Based state management:

  • View State
  • Hidden Fields
  • Cookies
  • Query Strings
  • Control State

The following techniques can be used to implement Server-Based state management:
  • Application State
  • Session State
  • Profile Properties

In which database is the information, such as membership, role management, profile, and Web parts personalization, stored?

The aspnetdb database stores all information.

How can you identify that the page is PostBack?

The Page object uses the IsPostBack property to check whether the page is posted back or not. If the page is postback, this property is set to true.

How can you enable impersonation in the web.config file?

To enable impersonation in the web.confing file, you need to include the <identity> element in the web.config file and set the impersonate attribute to true as shown in the following code snippet:
<identity impersonate = "true" />

What does the .WebPart file do?

The .WebPart file explains the settings of a Web Parts control that can be included to a specified zone on a Web page.

What are Custom User Controls in ASP.NET?

The custom user controls are the controls that are defined by developers. These controls are a mixture of custom behavior and predefined behavior. These controls work similar to other Web server controls.

What is a Cookie? Where is it used in ASP.NET?

Cookie is a lightweight executable program, which the server posts to client machines. Cookies store the identity of a user at the first visit of the Web site and validate them later on the next visits for their authenticity. The values of a cookie can be transferred between the user's request and the server's response.

Which method is used to post a Web page to another Web page?

The Respose.Redirect method is used to post a page to another page, as shown in the following code snippet: Response.Redirect("DestinationPageName.aspx");

How can you assign page specific attributes in an ASP.NET application?

The @Page directive is responsible for this.

Describe the complete lifecycle of a Web page.

When we execute a Web page, it passes from the following stages, which are collectively known as Web page lifecycle:

  • Page request - During this stage, ASP.NET makes sure the page either parsed or compiled and a cached version of the page can be sent in response
  • Start - During this stage sets the Request and Response page properties and the page check the page request is either a postback or a new request
  • Page Initialization - During this stage, the page initialize and the control's Unique Id property are set
  • Load - During this stage, if the request is postback, the control properties are loaded without loading the view state and control state otherwise loads the view state
  • Validation - During this stage, the controls are validated
  • Postback event handling - During this stage, if the request is a postback, handles the event
  • Rendering - During this stage, the page invokes the Render method to each control for return the output
  • Unload - During this stage, when the page is completely rendered and sent to the client, the page is unloaded. 

What are the event handlers that can be included in the Global.asax file?

The Global.asax file contains some of the following important event handlers:

  • Application_Error
  • Application_Start
  • Application_End
  • Session_Start
  • Session_End

What setting must be added in the configuration file to deny a particular user from accessing the secured resources?

To deny a particular user form accessing the secured resources, the web.config file must contain the following code:

<authorization >
<deny users="username" />
</authorization>

What is the use of PlaceHolder control? Can we see it at runtime?

The PlaceHolder control acts as a container for those controls that are dynamically generated at runtime. We cannot see it at runtime because it does not produce any visible output. It used only as a container.

Explain login controls.

Login controls are built-in controls in ASP.Net for providing a login solution to ASP.NET application. The login controls use the membership system to authenticate a user credentials for a Web site.

There are many controls in login controls.

  • ChangePassword control - Allows users to change their password.
  • CreateUserWizard control - Provides an interface to the user to register for that Web site.
  • Login control - Provides an interface for user authentication. It consists of a set of controls, such as TextBox, Label, Button, CheckBox, HyperLink.
  • LoginView control - Displays appropriate information to different users according to the user's status.
  • LoginStatus control - Shows a login link to users, who are not authenticated and logout link, who are authenticated
  • LoginName control - Displays a user name, if the user logs in.
  • PasswordRecovery control - Allows users to get back the password through an e-mail, if they forget. 

Explain how Cookies work. Give an example of Cookie abuse.

The server tells the browser to put some files in a cookie, and the client then sends all the cookies for the domain in each request. An example of cookie abuse is large cookies affecting the network traffic.

How can you implement the postback property of an ASP.NET control?

You need to set the AutoPostBack property to True to implement the PostBack property of controls.

Explain file-based dependency and key-based dependency

In file-based dependency, you have to depend on a file that is saved in a disk. In key-based dependency, you have to depend on another cached item.

What are the events that happen when a client requests an ASP.NET page from IIS server?

The following events happen when a client requests an ASP.NET page from the IIS server:

  1. User requests for an application resource.
  2. The integrated request-processing pipeline receives the first user request.
  3. Response objects are created for each user request.
  4. An object of the HttpApplication class is created and allocated to the Request object.
  5. The HttpApplication class processes the user request. 

What are HTTP handlers in ASP.NET?

HTTP handlers, as the name suggests, are used to handle user requests for Web application resources. They are the backbone of the request-response model of Web applications. There is a specific event handler to handle the request for each user request type and send back the corresponding response object.

Each user requests to the IIS Web server flows through the HTTP pipeline, which refers to a series of components (HTTP modules and HTTP handlers) to process the request. HTTP modules act as filters to process the request as it passes through the HTTP pipeline. The request, after passing through the HTTP modules, is assigned to an HTTP handler that determines the response of the server to the user request. The response then passes through the HTTP modules once again and is then sent back to the user.

You can define HTTP handlers in the <httpHandlers> element of a configuration file. The <add> element tag is used to add new handlers and the <remove> element tag is used to remove existing handlers. To create an HTTP handler, you need to define a class that implements the IHttpHandler interface.

What is the default timeout for a Cookie?

The default time duration for a Cookie is 30 minutes.

Suppose you want an ASP.NET function (client side) executed on the MouseOver event of a button. Where do you add an event handler?

The event handler is added to the Add() method of the Attributes property.

How does a content page differ from a master page?

A content page does not have complete HTML source code; whereas a master page has complete HTML source code inside its source file.