DOTNET Interview Questions And Answers

[TOP 50] DOTNET Interview Questions And Answers

Frequently asked DOTNET Interview Questions And Answers

DOTNET Interview Questions And Answers are as follows –

Question1: What is ASP.NET?

Answer: ASP.NET is an open-source server-side application framework designed for web developers to produce dynamic web pages with .NET framework. It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services.

Question 2: What is ASP.NET MVC framework?

Answer: ASP.NET MVC is a web application framework for the .NET Platform used for building full-stack web applications using the Model-View-Controller pattern.

Question 3: What is an ASP.NET Web API framework?

Answer: ASP.NET Web API is used purely for building backend web APIs which can be used by an array of clients, from the web to desktop to mobile. It forms the server component in the RESTful (Representational State Transfer) architecture.

Question 4: Which would be the right framework to be used ASP.NET MVC or ASP.NET Web API?

Answer: If one intends to build a server component that can be easily utilized by an array of clients then ASP.NET Web API is the way to go. If, however, the project is purely going to be used as a web application, then ASP.NET MVC is a more appropriate choice.

Question 5: What is the web.config file and what is used for?

Answer: The web.config file is crucial because it contains the configuration settings for the application. It keeps your entire configuration separate from your code so you can easily change settings without code changes. It also allows you to potentially encrypt the configuration settings for increased security.

Question 6: Which compiler is used in ASP.NET?

Answer: Roslyn is the name of the compiler used by .NET Framework.

Question 7: ASP.NET is open-source. Explain.

Answer: Microsoft is providing the full .NET server stack in open source which means it is a ‘free’ download. This includes ASP.NET, the .NET compiler, the .NET Core Runtime, Framework, and Libraries, enabling developers to build with .NET across Windows, Mac or Linux.

Question 8: Explain the request flow in ASP.NET MVC framework.

Answer: Request flow handles the request from the clients and passes it to the server. Request hits the controller coming from the client. Controller plays its role and decides which model to use in order to serve the request further, passing that model to view which then transforms the model and generates an appropriate response that is rendered to the client.

Question 9: What does “PostBack” mean in ASP.NET?

Answer: A PostBack happens when a user takes some action (like submitting a form) that sends information from the page to the server for processing via POST method.

Question 10: Explain the ASP.NET page life cycle in brief.

Answer: ASP.NET goes through a series of stages in the life cycle of each page.

Page request: The user requests a page. ASP.NET decides whether to compile it or serve it from a cache.

Page Start: The Request and Response objects are created.

Page Initialization: All page controls are initialized, and any themes are applied.

Page Load: ASP.NET uses the view state and control state properties to set the control properties. Default values are set in the controls.

Postback event handling: This event is triggered if the same page is loaded again.

Rendering: ASP.NET saves the view state for the page and writes the output of rendering to the output stream. It happens just before the complete web page is sent to the user.

Unload: The rendered page gets sent to the client. ASP.NET unloads page properties and performs cleanup. All unwanted objects are removed from memory.

Question 11: What is view state in ASP.NET?

Answer: View state is where data is used to preserve page values and control values of Web Forms during postback event handling. Data can be stored as hidden fields on the client web page.

Question 12: What is the difference between custom controls and user controls?

Answer: Custom controls are basically compiled code, i.e., DLLs. These can be easily added to the toolbox, so it can be easily used across multiple projects using a drag-and-drop approach. These controls are comparatively hard to create. But User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create but tightly coupled with respect to User Interface and code.

Question 13: What are the different Validators in ASP.NET?

Answer: ASP.NET validation controls define an important role in validating the user input data. Whenever the user gives input, it must always be validated before sending it across the various layers of an application. There are two types of validation in ASP.NET:

A) Client-Side Validation

B) Server-Side Validation

Client-Side Validation: When validation is done on the client browser, it is known as Client-Side Validation. You can use JavaScript to do the Client-Side Validation.

Server-Side Validation: When validation occurs on the server, then it is known as Server-Side Validation. Server-Side Validation is a secure form of validation. The main advantage of Server-Side Validation is if the user bypasses the Client-Side Validation, the problem can be caught on the server-side.

The following are the Validation Controls in ASP.NET:

  • RequiredFieldValidator Control
  • CompareValidator Control
  • RangeValidator Control
  • RegularExpressionValidator Control
  • CustomFieldValidator Control
  • ValidationSummary

Question 14: What does the method Finalize do in ASP.NET?

Answer: The Finalize method is used to perform cleanup operations on unmanaged resources held by an object. It puts an object in the finalization queue. The Object will then be collected by the garbage collector ready to be cleaned up.

Question 15: What is RedirectPermanent in ASP.Net?

Answer: RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns http 301 status code to the browser.

Question 16: What is the function of the LoginStatus Control?

Answer: LoginStatus control is used to display Login/Logout links based on the login/authorization status of the current user. If the user has successfully logged in, the Logout link will be displayed.

Question 17: What is a Repeater Control and what are the templates supported by the Repeater?

Answer: A Repeater is a Data-bound control. Data-bound controls are container controls. It creates a link between the Data Source and the presentation UI to display the data. The repeater control is used to display a repeated list of items. A Repeater has five inline templates to format it:

– Displays Header text for a Data Source collection and applies a different style for the Header text.

– Changes the background color or style of alternating items in a Data Source collection.

– It defines how each item is rendered from the Data Source collection.

– It will determine the separator element that separates each item in the item collection. It could be a HTML element.

– Displays a footer element for the Data Source collection.

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

Answer: In-Process and Out-of-Process are the two session state management options.

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

Out-of-Process Session state management stores data in an external server. All objects stored in session are required to be serializable.

Question 19: What is the difference Between Server.Transfer and Response.Redirect?

Answer: Server. Transfer sends information from one web request to another, all on the server side. A response is not sent to the browser. On the other hand, Response.Redirect sends an HTTP 302 message to the browser and causes a redirect in the browser.

Question 20: What is fragment caching?

Answer: Fragment caching refers to the caching of individual user controls within a Web Form. Each user control can have independent cache durations and implementations of how the caching behavior is to be applied. Fragment caching is useful when you need to cache only a subset of a page.

Question 21: What are web controls in ASP.NET?

Answer: Web controls are classes in the .NET framework. The controls have special tags understood by the server. They are created on the server and require a run at=”server” attribute to execute. They generate HTML code that is sent back to the browser.

Question 22: Give some examples of web controls.

Answer:

  • Button
  • Calendar
  • Checkboxlist
  • DropDownList
  • RadioButtonList

Question 23: What is a web service?

Answer: A Web service, in the context of .NET, is a component that resides on a Web server and provides information and services to other network applications using standard Web protocols such as HTTP and Simple Object Access Protocol (SOAP).

Question 24: What is the difference between session and application object?

Answer: The difference between session and application object is that all users share one Application object and with sessions, there is one session object for each user. 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 object stores session-specific information and the information are 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 applications configuration settings. By default, SessionID values are stored in cookies.

Question 25: What is Caching and what are the benefits of using it?

Answer: Caching is a mechanism that improves performance for an application by storing data in the memory for faster access. When the application accesses data from Cache (i.e. in-memory) instead of fetching it from the original data store (maybe a database), it definitely improves performance. But Caching benefits are not limited only to performance; it also improves application Scalability and Availability.

Question 26: What are the types of Authentication in ASP.NET?

Answer: There are three types of authentication available in ASP.NET:

Windows Authentication: This authentication method uses built-in Windows security features to authenticate a user.

Forms Authentication: Authenticates against a customized list of users or users in a database.

Passport Authentication: Validates against Microsoft Passport service which is basically a centralized authentication service.

Question 27: What is ASP.NET AJAX?

Answer: Microsoft has provided an implementation of AJAX functionality known as ASP.NET AJAX. AJAX stands for Asynchronous JavaScript and XML. This is a cross-platform technology that speeds up response time and reduces traffic between client and server. ASP.NET AJAX is a set of extensions to ASP.NET and comes with reusable AJAX controls.

Question 28: What is the REST architecture?

Answer: REST (Representational State Transfer) is an architectural style for designing applications and it dictates to use HTTP for making calls for communications instead of complex mechanism like CORBA, RPC or SOAP. There are few principles associated with REST architectural style:

Everything is a resource i.e. File, Images, Video, WebPage etc. Every Resource is identified by a Unique Identifier. Use simple and Uniform Interfaces. Everything is done via representation (sending requests from a client to server and receiving responses from server to client). Be Stateless- Every request should be an independent request.

Question 29: ASP.NET is cross-platform Explain.

Answer: ASP.NET applications can be developed and run on any operating systems like Windows, Linux, macOS, and Docker. Hence it is called a Cross-platform framework.

Question 30: What is Razor in ASP.NET

Answer: Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. The server-based code can create dynamic web content on the fly, while a web page is written to the browser. When a web page is called, the server executes the server-based code inside the page before it returns the page to the browser. By running on the server, the code can perform complex tasks, like accessing databases. Razor is based on ASP.NET, and designed for creating web applications. It has the power of traditional ASP.NET markup, but it is easier to use and easier to learn.

Question 31: What is ASP.NET Core?

Answer: ASP.NET Core is the open-source and cross-platform version of ASP.NET. The Windows-only versions of ASP.NET, that existed before ASP.NET Core, is typically just referred to as ASP.NET.

Question 32: Features of ASP.NET

Answer:

It uses C# and VB.NET languages to build the website.

It allows us to separate HTML layout with server-side code.

It allows us to make the same class name qualifying under a different namespace.

ASP.NET pages are compiled, not interpreted.

ASP.NET is a request processing engine. It takes an incoming request and passes it through its internal pipeline to an endpoint where a developer can attach code to process that request.

Question 33: What is the difference between Web Site and Web Application?

Answer: There are following differences between these two :

Web Site:

In a website, you cannot add multiple projects. There is no project file (.csproj or .vbproj). All the files in a folder structure are automatically included in the site.

By default, compilation produces multiple assemblies. The website is easy to create and deploy. You can use different .NET languages on a single web site such as VB.NET pages and C# pages can be used on a single website. You can edit a single page/file after deployment recompilation is not required.Choose a website when one developer will responsible for creating and managing an entire website. Since decoupling is not possible on the website. You cannot establish dependencies on the website.

Web Application

In a web application, you can add multiple projects. It has a Visual Studio project file (.csproj or .vbproj) stores information about the project like as the list of files that are included in the project, and any project-to-project references. By default, compilation of code files (excluding .aspx and .ascx files) produces a single assembly. It is easy to develop compared to the website.

You cannot use different .NET languages in a Web Application such asC# and VB.NET both cannot be used in a web application.

You cannot edit a single file. Recompilation is required.

The right choice for enterprise environments where multiple developers work for creating, testing and deployment. Different groups work on various components independently like one group work on the domain layer, other work on the UI layer hence, decoupling is possible here. You can establish dependencies in a Web Application.

Question 34: What is a round trip?

Answer: The trip of a Web page from the client to the server and then back to the client is known as a round trip. In ASP.NET Response.Redirect() causes a round trip.

Question 35: What is a Global.asax file?

Answer: The Global.asax file has been derived from the HttpApplication class. The Global.asax file is used to add application-level logic and processing. It does neither handles any UI related processing, nor it does support individual requests. It basically controls the following events.

  • Application_Start
  • Application_End
  • Session_Start
  • Session_End

Following are the important aspect of the use of the Global.asax file.

The code in the Global.asax is compiled when the web application is built for the first time.

Session level code and variables can be declared in Application_Start event.

Application level events are for the entire application and may be used for any user.

Session level events are user specific for the length of a session.

Question 36: What is the difference between Web.config and Machine.config file?

Answer: Both files are used to define configurations for your ASP.NET application. There are the following differences between these two configuration files.

Web.config

The Web.config is used to define application-level settings. If any setting is not specified in Web.config it inherits from Machine.config by default. Web.config is an XML-based configuration file for an ASP.NET application which includes the setting for Data Connection, Customizing Security, State Management, Memory Management, Error Handling and much more. It sometimes called application and session level configuration file. You can have more than one Web.config files in your ASP.NET application.

Machine.config

This file is at the highest level in the configuration hierarchy. You can find it at <WinDir>\Microsoft.NET\Framework\<version>\config\machine.config

Machine.config is used for defining server level setting. It defines the supported configuration file section and ASP.NET work process. It registers providers that can be used for advanced features such as profiles membership and role-based security. It is automatically installed while installing Visual Studio.NET. It sometimes called machine level configuration file. Only one Machine.config file can be at the machine level.

Question 37: How to define a connection string in Web.config file?

Answer: Following is the way to define a connection string in Web.config for SQL Server database.

<connectionStrings>

<add name=”strcon” connectionString=”Data Source=DonetApp; Initial Catalog=dotnetDB; Persist Security Info=True; User ID=asif@123; Password=123@asif” providerName=”System.Data.SqlClient”/>

</connectionStrings>

Question 38: What are various page events in ASP.NET?

Answer: Following are the page level events in ASP.NET.

PreInit: This is the first event of a page used to set values such as a master page.

Init: This event fires after each control have been initialized. You can use this event to change the initialized value of controls.

InitComplete: This event is raised after all initializations of a page and its controls have been completed.

PreLoad: This event fires before view state has been loaded for a page and its controls and before page postback processing. This event is useful when you need to write code after the page is initialized.

Load(PageLoad): Page load event is generally used to check postback and then sets control properties appropriately. After this event, the load event of child control is called.

ControlEvents(Postback): This event is called when a page or its controls causes postback such as ButtonClick event, SelectedIndexChanged event, CheckedChanged events etc.

LoadComplete: At this event, all controls are loaded even after additional processing can be done here.

PreRender: This event is taking place before view state is saved also it allows final changes to the page or its control.

SaveStateComplete: Any changes to the page’s controls at this point are ignored here. This event is useful if you need to write processing that requires the view state to be set.

Render: In real it is not an event this is actually a method of a page object and its controls. At this point, controls are rendered in client-side HTML , DHTML, and scripts for the browser.

Unload: This event is used to clean up code you can use it to manually release resources.

Question 39: What are server controls in ASP.NET?

The ASP.NET server controls are objects on the ASP.NET pages that run when the Web page is requested. Many server controls, such as button and text box, are similar to the HTML controls. In addition to the HTML controls, there are many controls, which include complex behaviour, such as the controls used to connect to data sources and display data.

Question 40: What is the difference between Hyperlink and LinkButton?

Answer: Hyperlink control does not have the Click and Command events; whereas the LinkButton control has these events, which can be handled in the code-behind file of the Web page.

Question 41: What are navigation controls?

Answer: Navigation controls help us to navigate in a Web application easily. These controls store all the links in a hierarchical or drop-down structure; thereby facilitating easy navigation in a Web application.

Question 42: How many navigation controls are in ASP.NET?

Answer: There are three navigation controls in ASP.NET.

SiteMapPath

Menu

TreeView

Question 43: What is the difference between client-side and server-side validations?

Answer: Client-side validations work at the client end with the help of scripting languages such as JavaScript or jQuery and VBScript. On the other hand, server-side validations work at the server end with the help of programming languages like C#, VB, F# etc. Server validations work when you submit or send data to the server.

Question 44: What is the difference between User Control and Custom Control?

Answer:  The differences between User Control and Custom Control are given below-

User Control

Custom Control

Built into .ascx file.

Built into a redistributable assembly (i.e. a DLL).

Generally used for static content.

Generally used for dynamic content.

It is easy to create and use as it inherits from server controls.

Comparatively difficult because you have to develop from scratch.

Can be only used with current applications.

Can be used with any number of applications.

Language dependent.

Language independent, a control created in C# can be used in VB.NET.

Cannot be added to Visual Studio toolbox.

Can be added to Visual Studio toolbox.

Question 45: What are Globalization and Localization?

Answer:  Globalization is the process of designing and developing an application that functions for multiple cultures or locales. In other words, Globalization is the process of designing and developing an application in such a way that it can be used by users of multiple cultures. Globalization makes your application ready for international markets. This process involves:

Identifying the culture and locale that must be supported by the application.

Designing features to support those cultures and locales.

Writing code that functions equally well with all the supported cultures and locales.

Localization is the process of customizing your application for a given culture or locale. In other words, Localization is the process of customizing your application in such a way that it behaves as per current culture or locale. Typically, Localization translates your application UI into current culture or locale.

Question 46: What is a Resource File?

Answer: ASP.NET provides resource files to implement globalization and localization. The resource file is an XML file having extension resx. Each resource in the resx file is in the form of a key-value pair. For each culture which your application needs to support create a separate resource file. For example, WebResources.en.resx is a resource file for English language and WebResources.hi.resx is a resource file for the Hindi language.

Question 47: What are Local Resources and Global Resources?

Answer: There are two types of resource files as given below:

Local Resources: Local resources are specific to a single web page and used for providing versions of a web page in different languages. These are stored in App_LocalResources folder.

Global Resources: Global resources are common for the whole web application and can be accessed by all the web pages. These are stored in the App_GlobalResources folder.

Question 48: What is Neutral Culture, Culture, and Language?

Answer: A neutral culture is a culture that is associated with a language but not with a country or region. For example, “en” for English and in for Hindi. Culture consists of language and the country or region. It is denoted by culture code which contains two lowercase letters denoting the language and two uppercase letters denoting the country or region like as en-US for English in the US, en-GB for UK etc. A language is any spoken language like English (en), Hindi (hi), and German (de) etc.

Question 49: What are the differences between GridView and DataGrid?

Answer: The differences between GridView and DataGrid are given below:

GridView

DataGrid

It was introduced with ASP.NET 2.0

It was introduced with ASP.NET 1.0

Built-in supports for Paging and Sorting.

For sorting, you need to handle SortCommand event and rebind grid required and for paging, you need to handle the PageIndexChanged event and rebind grid required

Built-in supports for Update and Delete operations.

Need to write code for implementing Update and Delete operations.

Supports auto format or style features.

This feature is not supported.

Performance is slow as compared to DataGrid

Performance is fast as compared to GridView.

Question 50: What are the differences between ListView and Repeater?

Answer: The differences between ListView and Repeater are given below :

ListView

Repeater

It was introduced with ASP.NET 3.5

It was introduced with ASP.NET 1.0

Built-in supports for paging and sorting.

Need to write custom code.

Built-in supports for Data grouping.

Need to write custom code.

Built-in supports for insert update and delete operation.

Need to write custom code.

Performance is slow as compared to Repeater

Performance is fast as compared to ListView

Related Posts:

For more Interview Questions And Answers click here

2 thoughts on “[TOP 50] DOTNET Interview Questions And Answers

  1. Pingback: C# Interview Questions And Answers - CloudNClear

  2. Pingback: TOP 100 Data Structure Interview Questions And Answers - CloudNClear

Comments are closed.