ASP.Net Interview Questions

What is ASP.Net?


It is a framework developed by Microsoft on which we can develop new generation web sites using web forms(aspx), MVC, HTML, Javascript, CSS etc. Its successor of Microsoft Active Server Pages(ASP). Currently there is ASP.NET 4.0, which is used to develop web sites. There are various page extensions provided by Microsoft that are being used for web site development. Eg: aspx, asmx, ascx, ashx, cs, vb, html, XML etc.

What’s the use of Response.Output.Write()?

We can write formatted output  using Response.Output.Write().

In which event of page cycle is the ViewState available?

After the Init() and before the Page_Load().

What is the difference between Server.Transfer and Response.Redirect?

In Server.Transfer page processing transfers from one page to the other page without making a round-trip back to the client’s browser.  This provides a faster response with a little less overhead on the server.  The clients url history list or current url Server does not update in case of Server.Transfer.

Response.Redirect is used to redirect the user’s browser to another page or site.  It performs trip back to the client where the client’s browser is redirected to the new page.  The user’s browser history list is updated to reflect the new address.

From which base class all Web Forms are inherited?

Page class.


What are the different validators in ASP.NET?

  1. Required field Validator
  2. Range  Validator
  3. Compare Validator
  4. Custom Validator
  5. Regular expression Validator
  6. Summary Validator

Which validator control you use if you need to make sure the values in two different controls matched?

Compare Validator control.

What is ViewState?

ViewState is used to retain the state of server-side objects between page post backs.

Where the viewstate is stored after the page postback?

ViewState is stored in a hidden field on the page at client side.  ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.

How long the items in ViewState exists?

They exist for the life of the current page.

What are the different Session state management options available in ASP.NET?

  1. In-Process
  2. Out-of-Process.

In-Process stores the session in memory on the web server.

Out-of-Process Session state management stores data in an external server.  The external server may be either a SQL Server or a State Server.  All objects stored in session are required to be serializable for Out-of-Process state management.

How you can add an event handler?

 Using the Attributes property of server side control.


What is caching?

Caching is a technique used to increase performance by keeping frequently accessed data or files in memory. The request for a cached file/data will be accessed from cache instead of actual location of that file.

What are the different types of caching?

ASP.NET has 3 kinds of caching :

  1. Output Caching,
  2. Fragment Caching,
  3. Data Caching.

Which type if caching will be used if we want to cache the portion of a page instead of whole page?

Get Global Python Certification

Get Started Python Online Training Now!

List the events in page life cycle?

1) Page_PreInit
2) Page_Init
3) Page_InitComplete
4) Page_PreLoad
5) Page_Load
6) Page_LoadComplete
7) Page_PreRender

Can we have a web application running without web.Config file?


Is it possible to create web application with both webforms and mvc?

Yes. We have to include below mvc assembly references in the web forms application to create hybrid application.

Can we add code files of different languages in App_Code folder?

No. The code files must be in same language to be kept in App_code folder.

What is Protected Configuration?

It is a feature used to secure connection string information.

Write code to send e-mail from an ASP.NET application?



MailMessage mailMess = new MailMessage ();
mailMess.From = [email protected];
mailMess.To = [email protected];
mailMess.Subject = “Test email”;
mailMess.Body = “Hi This is a test mail.”;
SmtpMail.SmtpServer = “localhost”;
SmtpMail.Send (mailMess);

MailMessage and SmtpMail are classes defined System.Web.Mail namespace.

How can we prevent browser from caching an ASPX page?

  We can SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property:

What is the good practice to implement validations in aspx page?

Client-side validation is the best way to validate data of a web page. It reduces the network traffic and saves server resources.

What are the event handlers that we can have in Global.asax file?

Application Events: Application_Start , Application_End, Application_AcquireRequestState, Application_AuthenticateRequest, Application_AuthorizeRequest, Application_BeginRequest, Application_Disposed,  Application_EndRequest, Application_Error, Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute,
Application_PreSendRequestContent, Application_PreSendRequestHeaders, Application_ReleaseRequestState, Application_ResolveRequestCache, Application_UpdateRequestCache

Session Events: Session_Start,Session_End

Which protocol is used to call a Web service?

HTTP Protocol

Can we have multiple web config files for an application?


What is the difference between web config and machine config?

Web config file is specific to a web application where as machine config is specific to a machine or server. There can be multiple web config files into an application where as we can have only one machine config file on a server.

Explain role based security ?

Role Based Security used to implement security based on roles assigned to user groups in the organization.

Then we can allow or deny users based on their role in the organization. Windows defines several built-in groups, including Administrators, Users, and Guests.

What is Cross Page Posting?

When we click submit button on a web page, the page post the data to the same page. The technique in which we post the data to different pages is called Cross Page posting. This can be achieved by setting POSTBACKURL property of  the button that causes the postback. Findcontrol method of PreviousPage can be used to get the posted values on the page to which the page has been posted.

How can we apply Themes to an application?

We can specify the theme in web.config file. Below is the code example to apply theme:

What is Redirect Permanent in ASP.Net?

Redirect Permanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns 301 Moved Permanently responses.

What is MVC?

MVC is a framework used to create web applications. The web application base builds on  Model-View-Controller pattern which separates the application logic from UI, and the input and events from the user will be controlled by the Controller.

Explain the working of passport authentication?

First of all it checks passport authentication cookie. If the cookie is not available then the application redirects the user to Passport Sign on page. Passport service authenticates the user details on sign on page and if valid then stores the authenticated cookie on client machine and then redirect the user to requested page

What are the advantages of Passport authentication?

All the websites can be accessed using single login credentials. So no need to remember login credentials for each web site.

Users can maintain his/ her information in a single location.

What are the Security Controls?

  • <asp:Login>: Provides a standard login capability that allows the users to enter their credentials
  • <asp:LoginName>: Allows you to display the name of the logged-in user
  • <asp:LoginStatus>: Displays whether the user is authenticated or not
  • <asp:LoginView>: Provides various login views depending on the selected template
  • <asp:PasswordRecovery>:  email the users their lost password

How do you register JavaScript for webcontrols ?

We can register javascript for controls using <CONTROL -name>Attribtues.Add(scriptname,scripttext) method.

In which event are the controls fully loaded?

Page load event.

what is boxing and unboxing?

Boxing is assigning a value type to reference type variable.

Unboxing is reverse of boxing ie. Assigning reference type variable to value type variable.

Differentiate strong typing and weak typing?

In strong typing, the data types of variable are checked at compile time. On the other hand, in case of weak typing the variable data types are checked at runtime. In case of strong typing, there is no chance of compilation error. Scripts use weak typing and hence issues arises at runtime.

How we can force all the validation controls to run?

The Page.Validate() method is used to force all the validation controls to run and to perform validation.

List all templates of the Repeater control?

  • ItemTemplate
  • AlternatingltemTemplate
  • SeparatorTemplate
  • HeaderTemplate
  • FooterTemplate

List the major built-in objects in ASP.NET?

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

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

The appSettings block in web config 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:

Which data type does the Range Validator control support?

The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.

What is the difference between an HtmlInputCheckBox control and an Html Input Radio Button control?

In Html Input CheckBox control, multiple item selection is possible whereas in Html Input RadioButton controls, we can select only single item from the group of items.

Which namespaces are necessary to create a localized application?



What are the different types of cookies in ASP.NET?

Session Cookie – Resides on the client machine for a single session until the user does not log out.

Persistent Cookie – Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.

What is the file extension of web service?

Web services have file extension .asmx..

What are the components of ADO.NET?

The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.

What is the difference between Execute Scalar and Execute Non-Query?

Execute Scalar returns output value where as Execute Non-Query does not return any value but the number of rows affected by the query. Execute Scalar used for fetching a single value and Execute Non-Query used to execute Insert and Update statements.

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.

Differentiate between a page theme and a global theme?

– Page theme applies to a particular web pages of the project. It is stored inside a subfolder of the App_Themes folder.
– Global theme applies to all the web applications on the web server. It is stored inside the Themes folder on a Web server.

What are Web server controls in ASP.NET?

– These are the objects on ASP.NET pages that run when the Web page is requested.
– Some of these Web server controls, like button and text box, are similar to the HTML controls.
– Some controls exhibit complex behavior like the controls used to connect to data sources and display data.

Differentiate between a HyperLink control and a LinkButton control?

– A HyperLink control does not have the Click and Command events while the LinkButton control has them, which can be handled in the code-behind file of the Web page.

How do Cookies work? Give an example of their abuse?

– The server directs the browser to put some files in a cookie. All the cookies are then sent for the domain in each request.
– An example of cookie abuse could be a case where a large cookie is stored affecting the network traffic.

What are Custom User Controls in ASP.NET?

– These are the controls defined by developers and work similar to other web server controls.
– They are a mixture of custom behavior and predefined behavior.

What is Role-based security?

– Used in almost all organization, the Role-based security assign certain privileges to each role.
– Each user is assigned a particular role from the list.
– Privileges as per role restrict the user’s actions on the system and ensure that a user is able to do only what he is permitted to do on the system.

What are the HTML server controls in ASP.NET?

– HTML server controls are similar to the standard HTML elements like those used in HTML pages.
– They expose properties and events for programatical use.
– To make these controls programmatically accessible, we specify that the HTML controls act as a server control by adding the runat=”server” attribute.

How would you turn off cookies on one page of your website?

– This can be done by using the Cookie.Discard property.
– It Gets or sets the discard flag set by the server.
– When set to true, this property instructs the client application not to save the Cookie on the hard disk of the user at the end of the session.

How would you create a permanent cookie?

– Permanent cookies are stored on the hard disk and are available until a specified expiration date is reached.
– To create a cookie that never expires set its Expires property equal to DateTime.maxValue.

Explain Culture and UICulture values.

– Culture value determines the functions like Date and Currency used to format data and numbers in a Web page.
– UICulture value determines the resources like strings or images loaded in a Web application for a Web page.

What is Global.asax file used for?

It executes application-level events and sets application-level variables.

Explain ASP.NET Web Forms?

– Web Forms are an extremely important part of ASP.NET.
– They are the User Interface (UI) elements which provide the desired look and feel to your web applications.
– Web Forms provide properties, methods, and events for the controls that are placed onto them.

What is event bubbling?

– When child control send events to parent it is termed as event bubbling.
– Server controls like Data grid, Data List, and Repeater can have other child controls inside them.

What are the various types of validation controls provided by ASP.NET?

ASP.NET provides 6 types of validation controls as listed below:

1. RequiredFieldValidator – It is used when you do not want the container to be empty. It checks if the control has any value or not.

2. RangeValidator – It checks if the value in validated control is within the specified range or not.

3. CompareValidator – Checks if the value in controls matches some specific values or not.

4. RegularExpressionValidator – Checks if the value matches a specific regular expression or not.

5. CustomValidator – Used to define User Defined validation.

6. Validation Summary – Displays summary of all current validation errors on an ASP.NET page.

Differentiate between namespace and assembly?

– Namespace is a naming convenience for logical design-time while an assembly establishes the name scope for types at run time.

Differentiate between early binding and late binding?

Early binding means calling a non-virtual method that is decided at a compile time while Late binding refers to calling a virtual method that is decided at a runtime.

What are the different kinds of assemblies?

There can be two types of assemblies.

Static assemblies – 

– They are stored on disk in portable executable files.
– It includes .NET Framework types like interfaces and classes, resources for the assembly (bitmaps, JPEG files, resource files etc.).

Dynamic assemblies – 

– They are not saved on disk before execution rather they run directly from memory.
– They can be saved to disk after they have been executed.

Differentiate between Structure and Class?

– Structures are value type while Classes are reference type.
– Structures can not have constructor or destructors while Classes can have them.
– Structures do not support Inheritance while Classes do support Inheritance.

What are the various types of Authentication?

There are 3 types of Authentication namely Windows, Forms and Passport Authentication.

Windows authentication – It uses the security features integrated in Windows NT and Windows XP OS to authenticate and authorize Web application users.

Forms authentication – It allows you to create your own list of users and validate their identity when they visit the Web site.

Passport authentication – It uses the Microsoft centralized authentication provider to identify users. Passport allows users to use a single identity across multiple Web applications. Passport SDK needs to be installed to use Passport authentication in your Web application.

Explain Server-side scripting and Client-side scripting?

– Server side scripting – All the script are executed by the server and interpreted as needed.
– Client side scripting means that the script will be executed immediately in the browser such as form field validation, email validation, etc. It is usually carried out in VBScript or JavaScript.

What is garbage collection?

It is a system where a run-time component takes responsibility for managing the lifetime of objects and the heap memory that they occupy

Explain serialization and deserialization.

– Serialization is the process of converting an object into a stream of bytes.
– Deserialization is the process of creating an object from a stream of bytes.

Both these processes are usually used to transport objects.

What are the various session state management options provided by ASP.NET?

– ASP.NET provides two session state management options – In-Process and Out-of-Process state management.
– In-Process stores the session in memory on the web server.
– Out-of-Process stores data in an external data source. This data source may be a SQL Server or a State Server service. Out-of-Process state management needs all objects stored in session to be serializable.

Explain the steps to be followed to use Passport authentication?

1. Install the Passport SDK.
2. Set the application’s authentication mode to Passport in Web.config.
3. Set authorization to deny unauthenticated users.
4. Use the PassportAuthentication_OnAuthenticate event to access the user’s Passport profile to identify and authorize the user.
5. Implement a sign-out procedure to remove Passport cookies from the user’s machine.

Explain the use of duration attribute of @OutputCache page directive?

– The @OutputCache directive’s Duration attribute determines how long the page is cached.
– If the duration attribute is set to 60 seconds, the Web form is cached for 60 seconds; the server loads the response in memory and retains that response for 60 seconds.
– Any requests during that time receive the cached response.
– Once the cache duration has expired, the next request generates a new response and cached for another 60 seconds.

Explain how a web application works?

A web application resides in the server and serves the client’s requests over internet. The client access the web page using browser from his machine. When a client makes a request, it receives the result in the form of HTML which are interpreted and displayed by the browser.

A web application on the server side runs under the management of Microsoft Internet Information Services (IIS). IIS passes the request received from client to the application. The application returns the requested result in the form of HTML to IIS, which in turn, sends the result to the client.

Explain the advantages of ASP.NET?

Following are the advantages of ASP.NET.

– Web application exists in compiled form on the server so the execution speed is faster as compared to the interpreted scripts.

– ASP.NET makes development simpler and easier to maintain with an event-driven, server-side programming model.

– Being part of .Framework, it has access to all the features of .Net Framework.

– Content and program logic are separated which reduces the inconveniences of program maintenance.

– ASP.NET makes for easy deployment. There is no need to register components because the configuration information is built-in.

– To develop program logic, a developer can choose to write their code in more than 25 .Net languages including VB.Net, C#, JScript.Net etc.

– Introduction of view state helps in maintaining state of the controls automatically between the postbacks events.

– ASP.NET offers built-in security features through windows authentication or other authentication methods.

– Integrated with ADO.NET.

– Built-in caching features.

Explain the different parts that constitute ASP.NET application?

Content, program logic and configuration file constitute an ASP.NET application.

Content files
Content files include static text, images and can include elements from database.

Program logic
Program logic files exist as DLL file on the server that responds to the user actions.

Configuration file
Configuration file offers various settings that determine how the application runs on the server.

Describe the sequence of action takes place on the server when ASP.NET application starts first time?

Following are the sequences:

IIS starts ASP.NET worker process – worker process loads assembly in the memory – IIS sends the request to the assembly – the assembly composes a response using program logic – IIS returns the response to the user in the form of HTML.

Explain the components of web form in ASP.NET?

Server controls
The server controls are Hypertext Markup Language (HTML) elements that include a runat=server attribute. They provide automatic state management and server-side events and respond to the user events by executing event handler on the server.

HTML controls
These controls also respond to the user events but the events processing happen on the client machine.

Data controls
Data controls allow to connect to the database, execute command and retrieve data from database.

System components
System components provide access to system-level events that occur on the server.

Describe in brief .NET Framework and its components?

.NET Framework provides platform for developing windows and web software. ASP.NET is a part of .Net framework and can access all features implemented within it that was formerly available only through windows API. .NET Framework sits in between our application programs and operating system.

The .Net Framework has two main components:

.Net Framework Class Library: It provides common types such as data types and object types that can be shared by all .Net compliant language.

The Common language Run time: It provides services like type safety, security, code execution, thread management, interoperability services.

Explore best ever Courses on Artificial Intelligence

Change Your Career. Change Your Life. Now!

What is an Assembly? Explain its parts?

An assembly exists as a .DLL or .EXE that contains MSIL code that is executed by CLR. An assembly contains interface and classes, it can also contain other resources like bitmaps, files etc. It carries version details which are used by the CLR during execution. Two assemblies of the same name but with different versions can run side-by-side enabling applications that depend on a specific version to use assembly of that version. An assembly is the unit on which permissions are granted. It can be private or global. A private assembly is used only by the application to which it belongs, but the global assembly can be used by any application in the system.

The four parts of an assembly are:

Assembly Manifest – It contains name, version, culture, and information about referenced assemblies.

Type metadata – It contains information about types defined in the assembly.

MSIL – MSIL code.

Resources – Files such as BMP or JPG file or any other files required by application.

Define Common Type System?

.Net allows developers to write program logic in at least 25 languages. The classes written in one language can be used by other languages in .Net. This service of .Net is possible through CTS which ensure the rules related to data types that all language must follow. It provides set of types that are used by all .NET languages and ensures .NET language type compatibility.

Define Virtual folder?

It is the folder that contains web applications. The folder that has been published as virtual folder by IIS can only contain web applications.

Describe the Events in the Life Cycle of a Web Application?

A web application starts when a browser requests a page of the application first time. The request is received by the IIS which then starts ASP.NET worker process (aspnet_wp.exe). The worker process then allocates a process space to the assembly and loads it. An application_start event occurs followed by Session_start. The request is then processed by the ASP.NET engine and sends back response in the form of HTML. The user receives the response in the form of page.

The page can be submitted to the server for further processing. The page submitting triggers postback event that causes the browser to send the page data, also called as view state to the server. When server receives view state, it creates new instance of the web form. The data is then restored from the view state to the control of the web form in Page_Init event.

The data in the control is then available in the Page_load event of the web form. The cached event is then handled and finally the event that caused the postback is processed. The web form is then destroyed. When the user stops using the application, Session_end event occurs and session ends. The default session time is 20 minutes. The application ends when no user accessing the application and this triggers Application_End event. Finally all the resources of the application are reclaimed by the Garbage collector.

What are the ways of preserving data on a Web Form in ASP.NET?

ASP.NET has introduced view state to preserve data between post back events. View state can’t avail data to other web form in an application. To provide data to other forms, you need to save data in a state variable in the application or session objects.

Define application state variable and session state variable?

These objects provide two levels of scope:

Application State
Data stored in the application object can be shared by all the sessions of the application. Application object stores data in the key value pair.

Session State
Session State stores session-specific information and the information is visible within the session only. ASP.NET creates unique sessionId for each session of the application. SessionIDs are maintained either by an HTTP cookie or a modified URL, as set in the application’s configuration settings. By default, SessionID values are stored in a cookie.

Describe the application event handlers in ASP.NET?

Following are the application event handlers:

This event occurs when the first user visits a page of the application.

This event occurs when there are no more users of the application.

This occurs at the beginning of each request to the server.

Occurs at the end of each request to the server.

This event occurs every time when any new user visits.

Occurs when the users stop requesting pages and their session times out.

Describe the Server Control Events of ASP.NET?

ASP.NET offers many server controls like button, textbox, DropDownList etc. Each control can respond to the user’s actions using events and event handler mechanism.

There are three types of server control events:

Postback events
This events sends the web page to the server for processing. Web page sends data back to the same page on the server.

Cached events
These events are processed when a postback event occurs.

Validation events
These events occur just before a page is posted back to the server.

How do you change the session time-out value?

The session time-out value is specified in the web.config file within session state element. You can change the session time-out setting by changing value of timeout attribute of session state element in web.config file.

Describe how ASP.NET maintains process isolation for each Web application?

In ASP.NET, when IIS receives a request, IIS uses aspnet_isapi.dll to call the ASP.NET worker process (aspnet_wp.exe). The ASP.NET worker process loads the Web application’s assembly, allocating one process space, called the application domain, for each application. This is the how ASP.NET maintains process isolation for each Web application.

Define namespace?

Namespaces are the way to organize programming code. It removes the chances of name conflict. It is quite possible to have one name for an item accidentally in large projects those results into conflict. By organizing your code into namespaces, you reduce the chance of these conflicts. You can create namespaces by enclosing a class in a Namespace…End Namespace block.

You can use namespaces outside your project by referring them using References dialog box. You can use Imports or using statement to the code file to access members of the namespaces in code.

What are the options in ASP.NET to maintain state?

Client-side state management
This maintains information on the client’s machine using Cookies, View State, and Query Strings.

A cookie is a small text file on the client machine either in the client’s file system or memory of client browser session. Cookies are not good for sensitive data. Moreover, Cookies can be disabled on the browser. Thus, you can’t rely on cookies for state management.

View State
Each page and each control on the page has View State property. This property allows automatic retention of page and controls state between each trip to server. This means control value is maintained between page postbacks. Viewstate is implemented using _VIEWSTATE, a hidden form field which gets created automatically on each page. You can’t transmit data to other page using view state.

Query strings can maintain limited state information. Data can be passed from one page to another with the URL but you can send limited size of data with the URL. Most browsers allow a limit of 255 characters on URL length.

Server-side state management
This kind of mechanism retains state in the server.

Application State
The data stored in the application object can be shared by all the sessions of the application. Application object stores data in the key value pair.

Session State
Session State stores session-specific information and the information is visible within the session only. ASP.NET creates unique sessionId for each session of the application. SessionIDs are maintained either by an HTTP cookie or a modified URL, as set in the application’s configuration settings. By default, SessionID values are stored in a cookie.

Database can be used to store large state information. Database support is used in combination with cookies or session state.

Explain the difference between Server control and HTML control?

Server events
Server control events are handled in the server whereas HTML control events are handled in the page.

State management
Server controls can maintain data across requests using view state whereas HTML controls have no such mechanism to store data between requests.

Browser detection
Server controls can detect browser automatically and adapt display of control accordingly whereas HTML controls can’t detect browser automatically.

Server controls contain properties whereas HTML controls have attributes only.

What is delegate?

A delegate acts like a strongly type function pointer. Delegates can invoke the methods that they reference without making explicit calls to those methods. It is type safe since it holds reference of only those methods that match its signature. Unlike other classes, the delegate class has a signature. Delegates are used to implement event programming model in .NET application. Delegates enable the methods that listen for an event, to be abstract.

Explain Exception handling in .Net?