ASP.NET Interview Questions and Answers - Test & Download!

Describe state management in ASP.NET.

State management is a technique to manage a state of an object on different request.

The HTTP protocol is the fundamental protocol of the World Wide Web. HTTP is a stateless protocol means every request is from new user with respect to web server. HTTP protocol does not provide you with any method of determining whether any two requests are made by the same person.

Maintaining state is important in any web application. There are two types of state management system in ASP.NET.

- Client-side state management
- Server-side state management

Explain client side state management system.

ASP.NET provides several techniques for storing state information on the client. These include the following:

view state: ASP.NET uses view state to track values in controls between page requests. It works within the page only. You cannot use view state value in next page.

control state: You can persist information about a control that is not part of the view state. If view state is disabled for a control or the page, the control state will still work.

hidden fields: It stores data without displaying that control and data to the user’s browser. This data is presented back to the server and is available when the form is processed. Hidden fields data is available within the page only (page-scoped data).

Cookies: Cookies are small piece of information that server creates on the browser. Cookies store a value in the user’s browser that the browser sends with every page request to the web server.

Query strings: In query strings, values are stored at the end of the URL. These values are visible to the user through his or her browser’s address bar. Query strings are not secure. You should not send secret information through the query string.

Explain server side state management system.

The following objects are used to store the information on the server:

Application State:
This object stores the data that is accessible to all pages in a given Web application. The Application object contains global variables for your ASP.NET application.

Cache Object:
Caching is the process of storing data that is used frequently by the user. Caching increases your application’s performance, scalability, and availability. You can catch the data on the server or client.

Session State:
Session object stores user-specific data between individual requests. This object is same as application object but it stores the data about particular user.

Explain cookies with example.

A cookie is a small amount of data that server creates on the client. When a web server creates a cookie, an additional HTTP header is sent to the browser when a page is served to the browser. The HTTP header looks like this:

Set-Cookie: message=Hello. After a cookie has been created on a browser, whenever the browser requests a page from the same application in the future, the browser sends a header that looks like this:

Cookie: message=Hello

Cookie is little bit of text information. You can store only string values when using a cookie. There are two types of cookies:

Session cookies
Persistent cookies.

A session cookie exists only in memory. If a user closes the web browser, the session cookie delete permanently.

A persistent cookie, on the other hand, can available for months or even years. When you create a persistent cookie, the cookie is stored permanently by the user’s browser on the user’s computer.

Creating cookie:
protected void btnAdd_Click(object sender, EventArgs e)
{
    Response.Cookies[“message”].Value = txtMsgCookie.Text;
}
// Here txtMsgCookie is the ID of TextBox.

Cookie names are case sensitive. Cookie named message is different from setting a cookie named Message.

The above example creates a session cookie. The cookie disappears when you close your web browser. If you want to create a persistent cookie, then you need to specify an expiration date for the cookie.
Response.Cookies[“message”].Expires = DateTime.Now.AddYears(1);

Reading Cookies
void Page_Load()
{
    if (Request.Cookies[“message”] != null)
    lblCookieValue.Text = Request.Cookies[“message”].Value;
}
// Here lblCookieValue is the ID of Label Control.

Describe the disadvantage of cookies.

- Cookie can store only string value.
- Cookies are browser dependent.
- Cookies are not secure.
- Cookies can store small amount of data.

What is Session object? Describe in detail.

HTTP is a stateless protocol; it can't hold the user information on web page. If user inserts some information, and move to the next page, that data will be lost and user would not able to retrieve the information. For accessing that information we have to store information. Session provides that facility to store information on server memory. It can support any type of object to store. For every user Session data store separately means session is user specific.



Storing the data in Session object.
Session [“message”] = “Hello World!”;

Retrieving the data from Session object.
Label1.Text = Session[“message”].ToString();

What are the Advantages and Disadvantages of Session?

Following are the basic advantages and disadvantages of using session.

Advantages:

- It stores user states and data to all over the application.

- Easy mechanism to implement and we can store any kind of object.

- Stores every user data separately.

- Session is secure and transparent from user because session object is stored on the server.

Disadvantages:

- Performance overhead in case of large number of user, because of session data stored in server memory.

- Overhead involved in serializing and De-Serializing session Data. Because In case of StateServer and SQLServer session mode we need to serialize the object before store.

Describe the Master Page.

Master pages in ASP.NET works as a template that you can reference this page in all other content pages. Master pages enable you to define the look and feel of all the pages in your site in a single location. If you have done changes in master page, then the changes will reflect in all the web pages that reference master pages. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.



ContentPlaceHolder control is available only on master page. You can use more than one ContentPlaceHolder control in master page. To create regions that content pages can fill in, you need to define ContentPlaceHolder controls in master page as follows:
<asp:ContentPlaceHolder ID=”ContentPlaceHolder1” runat=”server”>
</asp:ContentPlaceHolder>

The page-specific content is then put inside a Content control that points to the relevant ContentPlaceHolder:
<asp:Content ID=”Content1” ContentPlaceHolderID=”ContentPlaceHolder1” Runat=”Server”>
</asp:Content>

Note that the ContentPlaceHolderID attribute of the Content control points to the ContentPlaceHolder that is defined in the master page.

The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages.
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="CareerRide.master.cs" Inherits="CareerRide" %>

How you can access the Properties and Controls of Master Pages from content pages?

You can access the Properties and Controls of Master Pages from content pages. In many situations you need User’s Name in different content pages. You can set this value inside the master page and then make it available to content pages as a property of the master page.

We will follow the following steps to reference the properties of master page from content pages.

Step: 1

Create a property in the master page code-behind file.
public String UserName
{
    get
    {
        return (String)Session["Name"];
    }
    set
    {
        Session ["Name"] = value;
    }
}

Step: 2

Add the @ MasterTypedeclaration to the .aspx content page to reference master properties in a content page. This declaration is added just below the @ Page declaration as follows:
<%@ Page Title=" TEST" Language="C#" MasterPageFile="~/CareerRide.master" AutoEventWireup="true" CodeFile="CareerRideWelcome.aspx.cs" Inherits="CareerRideWelcome" %>

<%@ MasterTypeVirtualPath="~/CareerRide.master" %>

Step: 3

Once you add the @ MasterType declaration, you can reference properties in the master page using the Master class. For example take a label control that id is ID="Label1"
Label1.Text= Master.UserName ;

For referencing controls in the Master Page we will write the following code.

Content Page Code.
protected void Button1_Click(object sender, EventArgs e)
{
    TextBox txtName= (TextBox)Master.FindControl("TextBox1");
    Label1.Text=txtName.Text;
}

To reference controls in a master page, call Master.FindControl from the content page.

What are the different method of navigation in ASP.NET?

Page navigation means moving from one page to another page in your web site and another. There are many ways to navigate from one page to another in ASP.NET.

- Client-side navigation
- Cross-page posting
- Client-side browser redirect
- Client-Side Navigation

Client-side navigation:

Client-side navigation allows the user to navigate from one page to another by using client side code or HTML. It requests a new Web page in response to a client-side event, such as clicking a hyperlink or executing JavaScript as part of a button click.

Example:

Drag a HyperLink control on the form and set the NavigateUrl property to the desired destination page.

HyperLinkControl: Source
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Welcome.aspx"> Take a test from CareerRide </asp:HyperLink>

Suppose that, this control is placed on a Web page called CareerRide.aspx, and the HyperLink control is clicked, the browser simply requests the Welcome.aspx page.

Second method of client-side navigation is through JavaScript.

Example:

Take an HTML button control on web page. Following is the HTML code for the input button.
<input id="Button1" type="button" value="Go to next page" onclick="return Button1_onclick()" />

When the Button1 is clicked, the client-side method, Button1_onclick will be called. The JavaScript source for the Button1_onclick method is as follows:
<script language="javascript" type="text/javascript">
function Button1_onclick()
{
    document.location="NavigateTest2.aspx";
}

</script>

Cross-page posting:

Example:

Suppose that we have two pages, the first page is FirstPage.aspx and Second page is SecondPage.aspx. The First Page has a Button and TextBox control and its ID is Button1 and TextBox1 respectively. A Button control has its PostBackUrl property. Set this property to “~/SecondPage.aspx”. When the user clicks on Button, the data will send to SecondPage for processing. The code for SecondPage is as follows:
protected void Page_Load(object sender, EventArgs e)
{
    if(Page.PreviousPage == null)
    {
        Label1.Text = "No previous page in post";
    }
    else
    {
        Label1.Text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
    }
}

The second page contains a Label control and its ID is Label1.

The page that receives the PostBack receives the posted data from the firstpage for processing. We can consider this page as the processing page.The processing page often needs to access data that was contained inside the initial page that collected the data and delivered the PostBack. The previous page’s data is available inside the Page.PreviousPage property. This property is only set if a cross-page post occurs.

Client-side browser redirect:

The Page.Response object contains the Redirect method that can be used in your server-side code to instruct the browser to initiate a request for another Web page. The redirect is not a PostBack. It is similar to the user clicking a hyperlink on a Web page.

Example:
protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect ("Welcome.aspx");
}

In client-side browser redirect method an extra round trip to the server is happened.

Server-side transfer:

In this technique Server.Transfer method is used. The Transfer method transfers the entire context of a Web page over to another page. The page that receives the transfer generates the response back to the user’s browser. In this mechanism the user’s Internet address in his browser does not show the result of the transfer. The user’s address bar still reflects the name of the originally requested page.
protected void Button1_Click(object sender, EventArgs e)
{
    Server.Transfer("MyPage.aspx", false);
}

The Transfer method has an overload that accepts a Boolean parameter called preserve-Form. You set this parameter to indicate if you want to keep the form and query string data.

What does the Orientation property do in a Menu control?

- Orientation property of the Menu control sets the display of menu on a Web page to vertical or horizontal.
- Originally the orientation is set to vertical.

Differentiate between client-side and server-side validations in Web pages.

- Client-side validations happend at the client's side with the help of JavaScript and VBScript. This happens before the Web page is sent to the server.

- Server-side validations occurs place at the server side.

Differentiate between authentication and authorization.

- Authentication is the process of verifying the identity of a user using some credentials like username and password while authorization determines the parts of the system to which a particular identity has access.

- Authentication is required before authorization.

Example: If an employee authenticates himself with his credentials on a system, authorization will determine if he has the control over just publishing the content or also editing it.

What does the .WebPart file do?

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

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

In order to enable the impersonation in the web.config file, take the following steps:
- Include the <identity> element in the web.config file.
- Set the impersonate attribute to true as shown below:
<identity impersonate = "true" />

Differentiate between file-based dependency and key-based dependency.

- In file-based dependency, the dependency is on a file saved in a disk while in key-based dependency, you depend on another cached item.

Differentiate between globalization and localization.

- Globalization is a technique to identify the part of a Web application that is different for different languages and separate it out from the web application while in localization you try to configure a Web application so that it can be supported for a specific language or locale.
1 2 3 4 5 6 7 8

ASP.NET application life cycle and events processing
ASP.NET application life cycle - This section covers all about ASP.NET application life cycle and events processing
ASP.Net Server Control vs HTML control
ASP.Net Server Control vs HTML control - This article includes differences between Server Control and HTML control in ASP.NET.
ASP.NET Application and Session state variables, ways to preserve page data.
ASP.NET Application and Session - Here are the answers of interview questions on the topic ASP.NET Application and Session state variables.
Post your comment
Discussion Board
feedback
Very useful for everyone
venkat 11-28-2015
About asp.net
Simple and superb
k.sridhar 11-13-2015
asp.net tutorial comments
ONE PLACE !!! to find all most important asp.net knowledge-base questions. VERY VERY NICE!!!
PRATAP 10-5-2015
....
so nice....
Rampradeep 09-14-2015
asp.net
Vry nice easy ans
sangeetha 04-18-2015
ASP.Net
Very Nice Question_Answer.....so easy....
Vikas 04-15-2015
Define ASP.NET MVC
The ASP.NET MVC is an open source web application framework that implements the model–view–controller (MVC) pattern.


Dot Net Training Institutes in Chennai
gym.prathap 11-10-2014
Comment
These questions are really so good.
Anurag Singh 06-5-2014
good site
testy
test 04-21-2013
Request
I have a blog, I just want to keep your website online test link in my blog. please allow me to do this. My blog deals with interview FAQ, it is not as famous as your website but it has proper traffic.
thank you
thomas 05-7-2012
ASP.NET questions
Exhaustive and quality exercise, have been using this site for my preparation for interview.
Dilip 01-18-2012
ASP.NET interview questions
Difference between Namespace and Assembly

-Namespace can span multiple assemblies.
-Namespace logically groups class.
-Assembly is physical grouping of logical units.


Can you explain how to sign out in forms authentication?

FormsAuthentication.SignOut()

What are namespaces provided by .NET for data management?

System.data
System.data.oledb
System.data.sqlclient
System.xml


What are the fundamental objects in ADO.NET?

Datareader
Dataset

What is the basic method of dataadapter?

fill, fillschema, update


Explain the importance of Manifest in .NET

- .NET Manifest stores assembly metadata.
-Metadata is responsible in doing versioning of assembly, secure identify, resolve references to resources and classes
Ramesh 12-6-2011
ASP.NET interview questions
Can you explain the importance of Web.config?

It applies settings to each web application.


Explain the difference between dataset and datareader.

-Datareader provides forward-only and read-only access to data
-Dataset object can hold more than one table from the same data sources as well as the relationships between them.
-Dataset is a disconnected architecture
-Dataset cab persist contents while datareader cannot persist contents


What are the ways of authentication technique in ASP.NET?

Windows authentication
Passport authentication
Forms authentication


How to format data inside DataGrid.

By using DataFormatString property


Tell me which method to customize columns in DataGrid.

Template column


How do we force validation control to run?

Page.Validate


Can we disable client side script in validation?

Yes, set EnableClient script to false


How to find how to code was executed.

Tracing


How to find how the code was executed.

Session.abandan


What are different IIS isolation levels?

LOW (IIS process)
Medium (Pooled)
High (Isolated)
Tanvir 12-6-2011
ASP.NET interview questions
What are the modes of storing ASP.NET session?

-InProc
-StateServer
-SQLServer


What are the ways to maintain state?

Hidden fields, viewstate, hidden frames, cookies, query string


Tell me the sequence in which ASP.NET events are processed.

-Page_Init
-Page_Load
-Control events
-Page_Unload event


How to assign page specific attributes.

By using @Page directive


Where is ViewState information stored?

HTML hidden fields


Name the validation controls in ASP.NET.

RequiredFieldValidator
RangeValidator
CompareValidator
RegularExpressionValidator
CustomValidator
ValidationSummary
Ranveer 12-6-2011
ASP.NET interview questions
What are different types of JIT?

-Pre-JIT, Econo-JIT, Normal-JIT


How can we perform transactions in .NET?

-Open a database connection using open method of the connection object.
-Begin a transaction using the Begin Transaction method of the connection object.
-Execute the SQL commands using the command object.
-Commit or roll back the transaction using the commit or rollback method of the transaction object.
-Close the database connection.


What is reflection?

-Reflection is used to browse through the metadata information.
-Using reflection you can dynamically invoke methods using system.Type.Invokemember


Which class does the remote object has to inherit?

System.MarchalByRefObject


What are the different kinds of marshalling?

Marshal-by-value
Marshal-by-reference


What are different types of caching?

-Page Output caching
-Page Fragment Caching
Akash 12-6-2011
ASP.NET interview questions
What is a Assembly?

Assembly is a unit of deployment like an exe or a dll.


Explain the concept of strong names.

-Strong Name is same as GUID in COM components
-Strong Names helps GAC to differentiate between two versions
-It is required when we deploy assembly in GAC.
-Strong Names use public and private key concept


Difference between Namespaces and assembly.

Assembly is physical grouping of logical unit whereas Namespace is logically groups classes.

What are the different types of Assembly?

- Private assembly
- Public assembly


Where is version information stored of an assembly?

Stored in assembly in manifest.
Kedar 12-6-2011
ASP.NET interview questions and answers
Explain Global assembly cache, GAC.

Global assembly cache contains shared assemblies that are globally accessible to all .net application on the machine.
Shared assembly is installed in the GAC.

NIsha 11-22-2011
ASP.NET interview questions and answers
Difference between an EXE and a DLL.

An EXE is portable and executable with a entry point
A dll is not portable and executable since it has no entry point.

Disha 11-22-2011
ASP.NET interview questions and answers
Machine config and web config. Can you explain them?

Machine config sets the base configuration for all the .net assemblies running on the server.
Web config sets the base config for all the web app and override settings in machine configuration.

Prithvi 11-22-2011
ASP.NET interview questions and answers
Value types differ from reference types. Explain

variables of the value types directly contain their data.
Variables of the reference types store references to objects.
With reference types, it is possible for two variables to reference the same object,
With value types, the variables have their own copy of the data.
Pratik 11-22-2011