All IT Courses 50% Off
Dotnet Tutorials

ASP.NET Interview Questions and Answers

In this article, learn about the top interview questions and answers which can help you crack the interviews effortlessly.

  1. What is ASP.NET?

ASP.NET is a framework to develop new generation websites developed by Microsoft using Web Forms, MVC, HTML, JavaScript, etc. It is the successor of Microsoft Active Server Pages (ASP). Page Extensions are .aspx, .ascx, .vb, etc.

  1. What is the use of Response.Output.Write()?

This method is used to write the formatted output.

  1. In which stage of page cycle is the ViewState available?

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

  1. Explain the difference between Server.Transfer and Response.Redirect?

In Server.Transfer processing transfers from one page to the other page without making a round-trip back to the client’s browser, providing a faster response with a little less overhead on the server. The user URL history is not updated in the case of Server.Transfer.

All IT Courses 50% Off

In Response.Redirect processing transfers from one page to the other page with a trip back to the client’s browser. The user URL history is updated in the case of Response.Redirect.

  1. Name the different validators in ASP.NET.
  • Required field Validator
  • Range Validator
  • Compare Validator
  • Custom Validator
  • Regular expression Validator
  • Summary Validator
  1. Which validator control is used to make sure the values in two different controls matched?

Compare Validator control.

  1. Name the base class where all Web Forms are inherited.

Page Class.

  1. Define ViewState.

ViewState maintains the state of server-side objects between page postbacks.

  1. After the page postback, where the ViewState is stored?

ViewState is always stored in the hidden field on the page at the client-side and is transported to the client and then again back to the server. It is not stored on the server or any other external source.

  1. How long the items available in ViewState exists?

It exists for the life of the current page.

  1. Name and explain the different Session state management options available in ASP.NET.
  1. In-Process
  2. Out-of-Process.

In-Process Session state management stores the session in memory on the webserver.

Out-of-Process Session state management stores the data in an external server (SQL Server or a State Server). All objects that are stored in the session are required to be serializable interface for Out-of-Process state management.

  1. How to add an event handler?

With the help of Attributes property of server-side control.e.g.


  1. Define caching.

Caching is used to increase performance by keeping frequently accessed data or files in memory. The cached file/data can be requested and accessed from the cache instead of that file’s actual location.

  1. Name the types of caching.
  • Output Caching
  • Fragment Caching
  • Data Caching.
  1. Which caching will be used if you want to cache the portion of a page instead of the whole page?

Fragment Caching: It will cache the portion of the page generated by request. User controls can be created with the below code:

<%@ OutputCache Duration="120" VaryByParam="CategoryID;SelectedID"%>

  1. Name the events in the page life cycle.
  • Page_PreInit
  • Page_Init
  • Page_InitComplete
  • Page_PreLoad
  • Page_Load
  • Page_LoadComplete
  • Page_PreRender
  • Render
  1. Can we run a web application without the web.Config file?


  1. Can we create a web application with both webforms and MVC?

Yes, by including below MVC assembly references in the web forms application to create a hybrid application.


  1. Can code files of different languages be added in the App_Code folder?

No, the code files must be in the same language.

  1. Define the Protected Configuration.

Protected Configuration is a feature that is used to secure connection string information.

  1. Write a code to send an email from an ASP.NET application.
MailMessage mailMess = new MailMessage ();
mailMess.From = "";
mailMess.To = "";
mailMess.Subject = "Test email";
mailMess.Body = "Hi This is a test mail.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send (mailMess);

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

  1. How to prevent browsers from caching an ASPX page?

By using SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property:

Response.Cache.SetNoStore ();
Response.Write (DateTime.Now.ToLongTimeString ());

  1. What is the good practice for implementing validations on the aspx page?

The best way for validating data of a web page is Client-side validation that reduces the network traffic and saves server resources. It is also good to have Server-side validation because sometimes the browser bypasses the client-side validations.

  1. Name the event handlers available in the Global.asax file.

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

Session Events including Session_Start, Session_End

  1. Name the protocol used to call a Web service.

HTTP Protocol

  1. Are multiple web config files available for an application?


  1. Explain the difference between the web config file and the machine config file.

The Web config file is specific only to a web application, whereas the machine config file is specific to a machine or server. Multiple web config files can be there into an application, whereas only one machine config file is there on a server.

  1. What is role-based security?

Role-Based Security is used to implement security based on roles assigned to user groups in the organization. We can allow or deny the users based on their role in the organization. Several built-in groups that include Administrators, Users and Guests are available in Windows.

<AUTHORIZATION>< authorization >

< allow roles=”Domain_Name\Administrators” / >   < !– Allow Administrators in domain. — >

< deny users=”*”  / >                            < !– Deny anyone else. — >

< /authorization >

  1. Define Cross Page Posting.

After clicking on the submit button on the web page, the page post the data to the same page. The technique in which the data is posted to the different pages is called Cross Page Posting. This is achieved by setting the POSTBACKURL property of the button that causes the postback.

  1. How to apply Themes to an application?

Theme can be specified in web.config file with the help of below code:

<pages theme="Windows7" />
  1. What is RedirectPermanent?

It performs a permanent redirection from the requested URL to the specified URL. Once the redirection is complete, it returns 301 Moved Permanently responses.

  1. Explain MVC.

MVC (Model-View-Controller) is a framework to create web applications. It separates the application logic from UI, and the input and events from the user will be controlled by the Controller.

  1. How does passport authentication work?

It checks for the passport authentication cookie, and if the cookie is not available, then the application redirects the user to the Passport Sign-in page. It then authenticates the user details on the sign-in page and, if valid, then stores the authenticated cookie on the client machine and redirects the user to the requested page.

  1. Explain the advantages of Passport authentication.

All the websites are using single login credentials. So no need to remember the login credentials. Users can also maintain their information in a single location.

  1. Explain the Security Controls.
  • <asp:Login>: It provides a standard login functionality that allows the users to enter their credentials
  • <asp:LoginName>: It allows to display the name of the logged-in user
  • <asp:LoginStatus>: It checks and displays whether the user is authenticated or not
  • <asp:LoginView>: It provides various login views depending on the selected template
  • <asp:PasswordRecovery>: It emails the users their lost password
  1. How to register JavaScript for web controls?

By using <CONTROL -name>Attribtues.Add(scriptname,scripttext) method.

  1. Name the event where the controls fully loaded.

Page load event.

  1. Explain boxing and unboxing.

Boxing means assigning a value type to reference type variable.

Unboxing means reversing of boxing, i.e., assigning reference type variable to value type variable.

  1. What is the difference between the strong typing and weak typing?

In a strong typing method, the data types of variables are checked at compile time. But in the case of a weak typing method, the data types of variables are checked at runtime. 

  1. How to force all the validation controls to run?

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

  1. Name all templates of the Repeater control.
  • ItemTemplate
  • AlternatingltemTemplate
  • SeparatorTemplate
  • HeaderTemplate
  • FooterTemplate
  1. Name the major built-in objects.
  • Application
  • Request
  • Response
  • Server
  • Session
  • Context
  • Trace
  1. Name the appSettings Section in the web.config file.

The appSettings are the user-defined values.

<add key="Connection" value="server=local; pwd=password; database=default" />
  1. Which data type is supported by the RangeValidator?

Integer, Double, String, Currency, and Date.

  1. Explain the difference between an HtmlInputCheckBox control and an HtmlInputRadioButton control.

Multiple item selection is possible in HtmlInputCheckBoxcontrol, whereas we can select only a single item from the group of items in HtmlInputRadioButton controls.

  1. Which namespaces are important to create a localized application?
  1. Name the different types of cookies.

Non-Persistent Cookie: It persists on the client machine only for a single session until the user does not log out.

Persistent Cookie: It resides on a user’s machine for a period specified for its expiry, such as ten days, one month, and never.

  1. What is the file extension of the web service?

.asmx is the file extension of web service.

  1. Name the components of ADO.NET.

Dataset, Data Reader, Data Adaptor, Command, and connection.

  1. Explain the difference between ExecuteScalar and ExecuteNonQuery.

ExecuteScalar returns output value, but ExecuteNonQuery does not return any value; instead, it returns the number of rows affected by the query. ExecuteScalar is used for fetching a single value, but ExecuteNonQuery is used to execute Insert and Update statements.

Facebook Comments

Related Articles

Back to top button