Most Asked .NET Viva / Interview Questions with Answers

 





Q. What is the .NET framework?


Ans : The .NET framework supports an object-oriented approach that is used for building applications on windows. It supports various languages like C#, VB, Cobol, Perl, .NET, etc. It has a wide variety of tools and functionalities like class, library and APIs that are used to build, deploy and run web services and different applications.


.net logo - .net interview questions - edureka





Q.  What are the different components of .NET?


Ans : Following are the components of .NET


Common Language run-time

Application Domain

Common Type System

.NET Class Library

.NET Framework

Profiling




Q.  What do you know about CTS?


Ans : CTS stands for Common Type System. It follows certain rules according to which a data type should be declared and used in the program code. CTS also describes the data types that are going to be used in the application. We can even make our own classes and functions following the rules in the CTS, it helps in calling the data type declared in one program language by other programming languages.





Q.  What is CLR?


Ans : CLR stands for common language run-time, it is an important component of the .NET framework. We can use CLR as a building block of various applications and provides a secure execution environment for applications.


Whenever an application written in C# is compiled, the code is converted into an intermediate language. After this, the code is targeted to CLR which then performs several operations like memory management, security checks, loading assemblies, and thread management.




Q.  Explain CLS.


Ans : Common language specification helps the developers to use the components that are inter-language compatible with certain rules that come with CLS. It then helps in reusing the code in other .NET compatible languages.




Q.  What do you know about JIT?


Ans : JIT is a compiler which stands for Just In Time. It is used to convert the intermediate code into the native language. During the execution, the intermediate code is converted into the native language.




Q.  Why do we use Response.Output.Write()?


Ans : Response.Output.Write() is used to get the formatted output.




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


Ans : Response.Redirect basically redirects the user’s browser to another page or site. The history of the user’s browser is updated to reflect the new address as well. It also performs a trip back to the client where the client’s browser is redirected to the new page.


Whereas, Server.Transfer transfers from one page to the other without making any round-trip back to the client’s browser. The history does not get updated in the case of Server.Transfer.



Q.  What is the difference between namespace and assembly?


Ans : An assembly is a physical grouping of logical units whereas namespace groups classes. Also, a namespace can span multiple assemblies as well.




Q.  What is LINQ?


Ans : It is an acronym for Language integrated query which was introduced with visual studio 2008. LINQ is a set of features that extend query capabilities to the .NET framework language syntax that allows data manipulation irrespective of the data source. LINQ bridges the gap between the world of objects and the world of data.




Q.  What is MSIL?


Ans : MSIL is the Microsoft Intermediate Language, it provides instructions for calling methods, storing and initializing values, memory handling, exception handling and so on. All the .NET codes are first compiled to Intermediate Language.




Q.  From which base class all web Forms are inherited?


Ans : All web forms are inherited from page class.




Q. Explain the different parts of the assembly.


Ans : Following are the different parts of assembly:

Manifest: It has the information about the version of the assembly.

Type Metadata: Contains the binary information of the program

MSIL: Microsoft Intermediate Language Code

Resources: List of related files




Q.  How do you prevent a class from being inherited?


Ans : In C#, we can use the sealed keyword to prevent a class from being inherited.




Q.  What are the different types of constructors in c#?


Ans : Following are the types of constructors in C#:

Default Constructor

Parameterized constructor

Copy Constructor

Static Constructor

Private Constructor




Q.  What are the different types of assemblies?


Ans : There are two types of assemblies:


Private Assembly: It is accessible only to the application, it is installed in the installation directory of the application.

Shared Assembly: It can be shared by multiple applications, it is installed in the GAC.




Q.  What are MDI and SDI?


Ans : MDI( Multiple Document Interface): An MDI lets you open multiple windows, it will have one parent window and as many child windows. The components are shared from the parent window like menubar, toolbar, etc.

SDI( Single Document Interface): It opens each document in a separate window. Each window has its own components like menubar, toolbar, etc. Therefore it is not constrained to the parent window.




Q.  What is a garbage collector?

Ans : Garbage collector feature in .NET frees the unused code objects in the memory. The memory head is divided into 3 generations:

Generation 0: It stores short-lived objects.

Generation 1: This is for medium-lived objects.

Generation 2: It stores long-lived objects.

Collection of garbage refers to the collection of objects stored in the generations.




Q.  What is caching?

Ans : Caching simply means storing the data temporarily in the memory so that the data can be accessed from the memory instead of searching for it in the original location. It increases the efficiency of the application and also increases its speed.

Following are the types of caching:


Page caching

Data caching

Fragment caching




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


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




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


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





Q. From which base class all Web Forms are inherited?


Ans : Page class.




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


Ans : Required field Validator

Range Validator

Compare Validator

Custom Validator

Regular expression Validator

Summary Validator



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


Ans : Compare Validator control.




Q.  What is ViewState?


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




Q.  Where the viewstate is stored after the page postback?


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




Q.  How long the items in ViewState exists?


Ans : They exist for the life of the current page.



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


Ans : In-Process

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.



Q.  How you can add an event handler?


Ans : Using the Attributes property of server side control.


e.g.

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



Q.  What is caching?


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



Q.  What are the different types of caching?


Ans : ASP.NET has 3 kinds of caching :


Output Caching,

Fragment Caching,

Data Caching.



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


Ans : 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"%>




Q.  List the events in page life cycle.


Ans : 

1) Page_PreInit

2) Page_Init

3) Page_InitComplete

4) Page_PreLoad

5) Page_Load

6) Page_LoadComplete

7) Page_PreRender

8) Render



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

Ans :

Yes




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


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


System.Web.Mvc


System.Web.Razor


System.ComponentModel.DataAnnotations




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


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




Q.  What is Protected Configuration?


Ans : It is a feature used to secure connection string information.




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


Ans : 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 defined System.Web.Mail namespace.




Q.  How can we prevent browser from caching an ASPX page?


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


Response.Cache.SetNoStore ();

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




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

Ans :

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




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

Ans : 

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



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

Ans :

Yes.




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

Ans :

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.




Q.  Explain role based security ?

Ans :

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 >




Q.  What is Cross Page Posting?

Ans :

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.




Q.  How can we apply Themes to an asp.net application?

Ans : 

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


<configuration>


<system.web>


<pages theme="Windows7" />


</system.web>


</configuration>




Q.  What is RedirectPermanent in ASP.Net?

Ans :

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




Q.  What is MVC?

Ans : 

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.




Q.  Explain the working of passport authentication.


Ans :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




Q.  What are the advantages of Passport authentication?


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




Q.  How many languages are supported by .NET at present time?

Ans : When .NET was introduced first time, it supports many languages like VB.NET,C#,COBOL, and Perl etc. At present time it supports almost 44 languages.



Q.  How is it possible for .NET to support many languages?

Ans : The .NET language code is compiled to Microsoft Intermediate Language (MSIL). The generated code is called managed code. This managed code is run in .NET environment. So after compilation the language is not a barrier and the code can call or use function of another language also.




Q. Is ASP.NET different from ASP? If yes, explain how?

Ans : Yes, ASP.NET is different from ASP. These are the main differences:

ASP.NET is developed by Microsoft to create dynamic web applications while ASP (Active Server Pages) is a Microsoft's server side technology use to create web pages.

ASP.NET is compiled while ASP is interpreted.

ASP uses the technology named ADO while ASP.NET uses ADO.NET.

ASP.NET is completely object oriented while ASP is partially object oriented.




Q. What is the state management in ASP.NET?

Ans : State management is a technique that is used to manage a state of an object on different request. It is very important to manage state in any web application. There are two types of state management systems in ASP.NET.

Client side state management

Server side state management


 

Q. What is the difference between trace and debug?

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



Q. What are differences between system.stringbuilder and system.string?

Ans : The main differences between system.stringbuilder and system.string are:

system.stringbuilder is a mutable while system.string is immutable.

Append keyword is used in system.stringbuilder but not in system.string.



Q. What is the difference between int and int32?

Ans : There is no difference between int and int32. System. Int is an alias name for System.Int32 which is a .Net Class.



Q.  What is the difference between namespace and assembly?

Ans : An assembly is a physical grouping of logical units while namespace groups classes. A namespace can span multiple assemblies.





Q. Explain the differences between value type and reference type.

Ans : Following are the main differences between value type and reference type:


Value type contain variable while reference type doesn't contain value directly in its memory.

In reference type, memory is allocated in managed heap and in value type memory allocated in stack.

Reference type ex-class value type-struct, enumeration

Post a Comment

0 Comments