ASP.NET Interview Question And Answers


ASP.NET is a web application framework that Microsoft developed as a part of the .NET framework. This framework makes it easy to build dynamic website applications. Some other examples are the framework which includes Ruby on rails, express, and Django. Many of you may be curious about ASP.NET interview but before jumping to the questions. Here is a brief about the technology.

ASP.NET is a high-performance, cross-platform and free web application framework. Microsoft initially released the first version of the framework in 2016. After that, developers were provided with the ability to create cloud-enabled, modern applications. Since its release, the demand for ASP.NET has been roaring ever since. To choose the best applicant, there are now several ASP.NET interview questions and answers that employers ask to determine the skills and knowledge of the applicant.

Facts to know for ASP.NET interview

Several benefits have made this framework most sought-after. The primary benefit of the platform is that it is free of Windows OS. One can run and develop production-ready ASP.NET applications on Mac and Linux. This platform starts from scratch. Developers can use it to develop best performance applications. It is now amongst the fastest web application frameworks. Since it is open-source and has helped countless developers worldwide, the framework runs on the C#. 

Though Microsoft supports the legacy of ASP.NET, it will not develop it actively. The new core framework includes all the necessary enhancements and features. This platform offers the simplest and most versatile approach for creating and deploying web applications that focus on the browser, or device. ASP.NET is built on the common language runtime. It allows the programmers to successfully execute the code with the .Net language. It is compatible with HTTP and for web developers to develop web pages, applications, sites, and web services.

In this article, we have focused on providing the best primary ASP.NET interview questions for freshers. To limit the scope of the article, we have divided the questions into two primary sections. We have provided the basic ASP.NET interview, which covers the basics and focuses on understanding the app structure of the basic ASP.NET project.

ASP.NET interview questions and Answers

Certainly! Interviews can cover a wide range of topics, so it would be helpful if you do proper preparation before going for ASP.NET interview questions. Here is list of ASP.NET interview questions and answers.

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

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

2 . In which event of the page cycle is the ViewState available?

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

3 . 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 works to redirect the user’s browser to another page or site. It performs a trip back to the client where the client’s browser redirects to the new page. The user’s browser history list updates to reflect the new address.

4 . From which base class all Web Forms you can inherit?

Page class.

5 . What are the different validators in ASP.NET?

It is most popular ASP.NET interview question. The following are 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

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

Compare Validator control.

7 . What is ViewState? (ASP.NET interview)

ViewState retains the state of server-side objects between page post backs.

8 . Where viewstate stores 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.

9 . How long do the items in ViewState exist?

They exist for the life of the current page.

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

  1. 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. You need to serialise all objects stored in session for Out-of-Process state management.

11 . How can you add an event handler?

Using the Attributes property of server side control.

e.g.

btnSubmit.Attributes.Add("onMouseOver","JavascriptCode();")

12 . What is caching?

Caching is a technique that increases performance by keeping frequently accessed data or files in memory. You can access a cached file/data from cache instead of the actual location of that file.

13 . What are the different types of caching? ASP.NET interview

ASP.NET has 3 kinds of caching :

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

14 . Which type of caching you can use if we want to cache the portion of a page instead of the whole page?

Fragment Caching: It caches the portion of the page generated by the request. For that, we can create user controls with the below code:

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

15 . List the events in the page life cycle.

1) Page_PreInit

2) Page_Init

3) Page_InitComplete

4) Page_PreLoad

5) Page_Load

6) Page_LoadComplete

7) Page_PreRender

8) Render

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

Yes.

17 . Is it possible to create web applications with both webforms and mvc?

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

System.Web.Mvc

System.Web.Razor

System.ComponentModel.DataAnnotations

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

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

19 . Write code to send email from an ASP.NET application?

MailMessage mailMess = new MailMessage ();
mailMess.From = "abc@gmail.com";
mailMess.To = "xyz@gmail.com";
mailMess.Subject = "Test email";
mailMess.Body = "Hi This is a test mail.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send (mailMess);

MailMessage and SmtpMail are classes that you can define in the System.Web.Mail namespace.

20 . How can we prevent browsers from caching an ASPX page?

It is again one of the most popular ASP.NET interview question. We can SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property:

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

21 . What is the good practice to implement validations in the 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.

22 . Which protocol works to call a Web service?

HTTP Protocol

23 . Can we have multiple web config files for an asp.net application?

Yes.

24 . What is the difference between web config and machine config?

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

25 . Explain role based security? ASP.NET interview

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.

<AUTHORIZATION>< authorization >
< allow roles="Domain_Name\Administrators" / >   < !-- Allow Administrators in domain. -- >
< deny users="*"  / >                            < !-- Deny anyone else. -- >
< /authorization >

26 . What is the ASP.NET MVC framework?

Before going for ASP.NET interview, you must certainly prepare for this question!

ASP.MVC is a web application framework that is lightweight and has highly testable features. ASP.NET supports 3 different types of components namely Model, View, and Controller.

  • Model Layer: The Model component corresponds to all or any of the data-related logic that the user works with. This will represent either the info that transfers between the View and Controller components or the other business logic-related data. For instance, a Customer object will retrieve the customer information from the database, manipulate it, and update its data back to the database or use it to render data.
  • View Layer: The View component employs for all the UI logic of the appliance. For instance, the Customer view will include all the UI components like text boxes, dropdowns, etc. that the ultimate user interacts with.
  • Controller: Controllers act as an interface between Model and consider components to process all the business logic and incoming requests, manipulate data using the Model component, and interact with the Views to render the ultimate output. For instance, the Customer controller will handle all the interactions and inputs from the Customer View and update the database using the Customer Model. An equivalent controller is going to be wont to view the Customer data.

27 . Which would be the right framework to use: ASP.NET MVC or ASP.NET Web API? ASP.NET interview

  • Asp.Net Web API works to make all  HTTP services in a simple and basic way that returns only information, not view.
  • Web API helps to build REST-ful services over the .NET Framework, and it additionally supports content negotiation, self-facilitating which are not in MVC.
  • Web API additionally deals with returning information specifically designed like JSON, XML, or some other dependent on the Accept header in the solicitation, and you don’t stress over that. MVC just returns information in JSON design utilizing Json Result.

28 . What is Server control?

ASP.NET has Server Controls features, Which provide facilities to manipulate values of the controls on the Server-Side. This is especially helpful while we want to create validating and dynamically web forms.

29 . What is the web.config file?

A configuration file (web.config) works to oversee different settings that characterize a website. The settings are in XML files that are independent of your application code. In this manner, you can configure settings freely from your code. This file is inside the application root directory.

30 . Which compiler works in ASP.NET?

To compile an ASP.NET program, the  .NET framework used the Roslyn compiler.

31 . ASP.NET is open-source. Explain?

ASP.NET is an open-source web framework for building web applications on the .NET (dotNET) framework. It is made by Microsoft and variant 1.0 was delivered in 2002 to allow users to develop dynamic web applications, services, and sites. Also, the framework works with the standard HTTP convention, which is the standard protocol that you can utilize across all web-based applications.  ASP.NET is the replacement to the ASP (Active Server Pages) innovation and was a significant update as far as adaptability and power. It is an expansion of the .NET framework with extra tools and libraries for building things on the web, including web applications and websites.  The ASP.NET cross-plate form version is popular as ASP.NET Core. Also, ASP.NET is still have updates.

32 . Explain the Global.asax file? (ASP.NET interview)

Global.asax is an optional file that resides in the application root directory. This file works to handle higher-level application events, for example, Application_Start, Application_End, Session_Start, Session_End, and so on. It is additionally popular as the ASP.NET Application File..Global.asax contains a Class representing your application as a whole. Also, at run time, this file parses and compiles into a dynamically created .NET Framework class derived from the HTTP Application base class. We can convey this file as an assembly in the \bin catalog of an ASP.NET application. The Global.asax record itself works in a way that if a user demands the document, the request is denied. External users can’t download or see the code written inside it.

33 . How many types of Server controls works in ASP.NET? (ASP.NET interview)

There are mainly four different types of  Server-side controls in ASP.NET :

  • HTML server controls
  • Web Server controls
  • User controls
  • Validation controls

34 . What does “PostBack” mean in ASP.NET? (ASP.NET interview)

A PostBack is the process of presenting an ASP.NET page to the server for processing. PostBack is done if certain credentials of the page are to be checked against certain sources, (for example, confirmation of username and secret key/password using a database). This is something that a client machine is not able to achieve and subsequently, these details must be ‘posted back’ on the server. So, we can say that a postback event occurs on the client-side but is handled by the code in a copy of the page running on the server.

35 . Explain the difference between Web.config and Machine.config file? (ASP.NET interview)

There is some key difference between Web.config and Machine.config file below:

  • Generally, the machine.config record is the master configuration document on your framework with a lot of default settings. And Web.config is the file for the local settings that you can apply for a website which stores configuration information in XML format.
  • Generally, the settings of the Machine.config file applies to the entire asp.net applications on your server while the settings made in the Web.config file are applied to that specific web application only.
  • Usually, each .NET Framework form has only one machine.config file, simultaneously, each web application has its own web.config file. Directories inside a web application can have web.config files as well.
  • The machine.config is shared values among numerous applications on the server, while Web.config documents contain application explicit things, for example, database connection strings.
  • Suppose if you want any improvements in the web.config, then the web application will promptly load the changes but in the machine.config case you should restart the application.
  • The machine.config document will automatically be introduced when you install Visual Studio.Net and it resides in the c:\windows\microsoft.net\framework\version\config folder whereas web.config will automatically be made when you make an ASP.Net web application project.
  • Machine.config is the design configuration file for all the applications in the IIS, but Web. config is a configuration file for a specific application.

36 . What is IIS? (ASP.NET interview)

IIS stands for Internet Information Services. It is created by Microsoft to provide Internet-based services to ASP.NET Web applications.

37 . What is the usage of IIS? (ASP.NET interview)

Following are the main usage of IIS:

  • IIS is used to make your computer work as a Web server and provides the functionality to develop and deploy Web applications on the server.
  • IIS handles the request and response cycle on the Web server.
  • IIS also offers the services of SMTP and FrontPage server extensions.
  • The SMTP is used to send emails and use FrontPage server extensions to get the dynamic features of IIS, such as form handler.

38 . What is a multilingual website? (ASP.NET interview)

If a website provides content in many languages, it is known as a multilingual website. It contains multiple copies of its content and other resources, such as date and time, in different languages.

39 . What is the parent class of all web server control? (ASP.NET interview)

System.Web.UI.Control class

40 . What is the difference between ASP.NET Webforms and ASP.NET MVC? (ASP.NET interview)

ASP.NET Webforms uses the page controller approach for rendering layout. In this approach, every page has its controller.

On the other hand, ASP.NET MVC uses the Front Controller approach. In this approach, there is a common controller for all pages.

41 . Define the types of configuration files in ASP.NET interview

There are two types of configuration files:

  • Application Level config = Web.config.
  • Machine Level config = Machine.config.

42 . What is the difference between a session object and application object? (ASP.NET interview)

The session object is used to maintain the session of each user. A session id is generated if a user enters in the application and when the user leaves the application, the session id is automatically deleted.

On the other hand, the application object is used to store the information and access variables from any page in the application.

43 . What is the difference between trace and debug? (ASP.NET interview)

Debug class is used to debug builds. Trace class is used for both debug and release builds.

44 . What is the difference between client-side and server-side validations in WebPages? (ASP.NET interview)

The client-side validation happens at the client’s side with the help of JavaScript and VBScript. This validation has occurred before the Web page is sent to the server.

The server-side validation happens at the server side.

45 . What is the difference between file-based dependency and key-based dependency? (ASP.NET interview)

File-based dependency: File-based dependency facilitates you to save the dependency on a file in a disk.

Key-based dependency: In key-based dependency, you depend on another cached item.

46 . What is the difference between globalization and localization? (ASP.NET interview)

Globalization: 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.

Localization: In localization, you try to configure a Web application so that it can be supported for a specific language or locale.

47 . What is the difference between a page theme and a global theme? (ASP.NET interview)

Page Theme: The page theme is applied to particular web pages of the project. It is stored inside a subfolder of the App_Themes folder.

Global Theme: The Global theme is applied to all the web applications on the web server. It is stored inside the Themes folder on a Web server.

48 . What is the difference between early binding and late binding? (ASP.NET interview)

Early Binding: In early binding, a non-virtual method is called which is decided at a compile time.

Late Binding: In late binding, a virtual method is called which is decided at runtime.

49 . What is the difference between server-side scripting and client-side scripting? (ASP.NET interview)

Server-side scripting: In server-side scripting, all the script are executed by the server and interpreted as needed.

Client-side scripting: In client-side scripting, the script will be executed immediately in the browser such as form field validation, email validation, etc.

The client-side scripting is usually carried out in VBScript or JavaScript.

50 . How to sign out from forms authentication? (ASP.NET interview)

FormsAuthentication.Signout() method is used to sign out from forms authentication.

These were some of the most popular ASP.NET interview questions that you must go through before going for any ASP.NET interview.