Dotnet Interview Notes part 1

Dotnet Interview Notes part 1

1.What is .NET?

NET is an integral part of many applications running on Windows and provides common functionality for those applications to run. This download is for people who need .NET to run an application on their computer. For developers, the .NET Framework provides a comprehensive and consistent programming model for building applications that have visually stunning user experiences and seamless and secure communication.

2.How many languages .NET is supporting now?

When .NET was introduced it came with several languages.

VB.NET,

C#,

COBOL

and

Perl, etc.

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

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.

Class

Object

Class is the definition of an object

An object is an instance of a class.

It is a template of the object

A class does not become an object unless instantiated

It describes all the methods, properties, etc

An object is used to access all those properties from the class.

what do you know about boxing and unboxing?

Boxing

Unboxing

Implicit

Explicit

Converting a value type to the type object

Extracting the value type from the object

eg : obj myObject = i;

eg : i = (int)myObject;

Differentiate between constants and read-only variables.

Constants

Read-only Variables

Evaluated at compile time

Evaluated at run-time

Support only value type variables

They can hold the reference type variables

They are used when the value is not changing at compile time

Used when the actual value is unknown before the run-time

Cannot be initialized at the time of declaration or in a constructor

Can be initialized at the time of declaration or in a constructor

From which base class all web Forms are inherited?

All web forms are inherited from page class.

What are the different types of constructors in c#?

Following are the types of constructors in C#:

  • Default Constructor

  • Parameterized constructor

  • Copy Constructor

  • public class Employee

  • {

  • public string firstName;

  • public string lastName;

  • public string position;

  • public int salary;

  • public Employee()

  • {

  • }

  • // Copy constructor.

  • public Employee(Employee employee)

  • {

  • firstName = employee.firstName;

  • lastName = employee.lastName;

  • position = employee.position;

  • salary = employee.salary;

  • }

  • }

  • Static Constructor

Characteristic of static constructor

  1. A static constructor does not take any access modifiers.

  2. A static constructor does not have a parameter.

  3. A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.

  4. A static constructor cannot be called directly.

  5. The user has no control over when the static constructor is executed in the program.

  6. A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.

  7. A class can have only one static constructor.

  8. It can access only static members of a class.

  9. Private Constructor

A private constructor is a special instance constructor. It is generally used in classes that contain static members only. If a class has one or more private constructors and no public constructors, other classes (except nested classes) cannot create instances of this class. The use of private constructor is to serve singleton classes. A singleton class is one which limits the number of objects created to one. Using private constructor we can ensure that no more than one object can be created at a time

  • One use of private constructor is when we have the only static member.

  • It provides the implementation of singleton class pattern.

  • Once we provide constructor (private/public/any) the compiler will not add the no parameter public constructor to any class.

use of static constructor. Why and when would we create a static constructor and is it possible to overload one?

No you can’t overload it; a static constructor is useful for initializing any static fields associated with a type (or any other per-type operations) — useful in particular for reading required configuration data into readonly fields, etc.

It is run automatically by the runtime the first time it is needed (the exact rules there are complicated (see “beforefieldinit”) and changed subtly between CLR2 and CLR4). Unless you abuse reflection, it is guaranteed to run at most once (even if two threads arrive at the same time).

List the events in the page life cycle.

Following are the events in the page life cycle:

· Page_PreInit

· Page_Init

· Page_InitComplete

· Page_PreLoad

· Page_Load

· Page_LoadComplete

· Page_PreRender

· Render

· What is the code to send an email from an ASP.NET application?

1

2

3

4

5

6

7

8

mail message = new mail();

message.From = “”;

message.To = “”;

message.Subject = “Test”;

message.Body = “hello”;

SmtpMail.SmtpServer = “localhost”;

SmtpMail.Send(message);

What is cross-page posting?

Whenever we click on a submit button on a page, the data is stored on the same page. But if the data is stored on a different page, it is known as a cross-page posting.

Cross-page posting can be achieved by POSTBACKURL property which causes the postback.

FindControl method can be used to get the values that are posted on this page to which the page has been posted.

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

  • Session Cookie: It resides on the client machine for a single session until the user logs out.

  • Persistent Cookie: Resides on the user machine for a period specified for its expiry. It may be an hour, a month or never.

What is the difference between ExecuteScalar and ExecuteNonQuery?

ExecuteScalar

ExecuteNonQuery

Returns the output value

Does not return any value

Used for fetching a single value

Used to execute insert and update statements

Does not return the number of affected rows

Returns the number of affected rows.

What is the difference between a stack and a heap?

Stack

Heap

Stored value type

Stored reference type

A stack is responsible for keeping track of each executing thread and its location.

The heap is responsible for keeping track of the more precise objects or data.

ASP.NET Core Running under IIS

IIS acts as a front end proxy to the backend Kestrel Console application that hosts the .NET based Kestrel Web server.

In this scenario, IIS uses a very low level and early pipeline AspNetCoreModule that intercepts all requests pointed at it (via a module mapping) and then forwards those requests to Kestrel on a different port. Requests come in on standard HTTP ports (80 and 443 for SSL) and IIS proxies the incoming requests to a different port that Kestrel is listening on.

By default the module configuration forwards all requests to Kestrel, but you have some very limited control over what gets routed to the module.

**w3wp.exe process (there may be more than one for each application pool so you have find the right one which you can do by looking at the command line arguments in Process Explorer or Task Manager) and the `dotnet.exe`** process

You can see that both **w3wp.exe and `dotnet.exe` - which runs the Kestrel Web server process - are using the same NETWORK SERVICE** account. Keep in mind that you may have multiple application pools, and multiple instances of .NET Core Application's running at the same time in which case each application pool and kestrel process will launch in their associated security context.

How to enable Attribute Routing?

Just add the method — “MapMvcAttributeRoutes()” to enable attribute routing as shown below

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute(“{resource}.axd/{pathInfo}”);*

//enabling attribute routing

routes.MapMvcAttributeRoutes();

//convention-based routing

routes.MapRoute

(

name: “Default”,

url: “{controller}/{action}/{id}”,

defaults: new { controller = “Customer”, action = “GetCustomerList”, id = UrlParameter.Optional }

);

}

What is routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

.axd files don’t exist physically. ASP.NET uses URLs with .axd extensions (ScriptResource.axd and WebResource.axd) internally, and they are handled by an HttpHandler.

Therefore, you should keep this rule, to prevent ASP.NET MVC from trying to handle the request instead of letting the dedicated HttpHandler do it.

9. Explain JSON Binding?

JavaScript Object Notation (JSON) binding support started from MVC3 onwards via the new JsonValueProviderFactory, which allows the action methods to accept and model-bind data in JSON format. This is useful in Ajax scenarios like client templates and data binding that need to post data back to the server.

Active Directory Federation Services (ADFS):

Active Directory Federation Services (ADFS) is a Single Sign-On (SSO) solution created by Microsoft. As a component of Windows Server operating systems, it provides users with authenticated access to applications that are not capable of using Integrated Windows Authentication (IWA) through Active Directory (AD).

Developed to provide flexibility, ADFS gives organizations the ability to control their employees’ accounts while simplifying the user experience: employees only need to remember a single set of credentials to access multiple applications through SSO.

How does ADFS work?

ADFS manages authentication through a proxy service hosted between AD and the target application. It uses a Federated Trust, linking ADFS and the target application to grant access to users. This enables users to log onto the federated application through SSO without needing to authenticate their identity on application directly.

The authentication process generally follows these four steps:

  1. The user navigates to a URL provided by the ADFS service.

  2. The ADFS service then authenticates the user via the organization’s AD service.

  3. Upon authenticating, the ADFS service then provides the user with an authentication claim.

  4. The user’s browser then forwards this claim to the target application, which either grants or denies access based on the Federated Trust service created.

Grant limited access to Azure Storage resources using shared access signatures (SAS)

A shared access signature (SAS) provides secure delegated access to resources in your storage account without compromising the security of your data. With a SAS, you have granular control over how a client can access your data.

Types of shared access signatures

Azure Storage supports three types of shared access signatures:

· User delegation SAS (preview). A user delegation SAS is secured with Azure Active Directory (Azure AD) credentials and also by the permissions specified for the SAS. A user delegation SAS applies to Blob storage only.

For more information about the user delegation SAS, see Create a user delegation SAS (REST API).

· Service SAS. A service SAS is secured with the storage account key. A service SAS delegates access to a resource in only one of the Azure Storage services: Blob storage, Queue storage, Table storage, or Azure Files.

For more information about the service SAS, see Create a service SAS (REST API).

· Account SAS. An account SAS is secured with the storage account key. An account SAS delegates access to resources in one or more of the storage services. All of the operations available via a service or user delegation SAS are also available via an account SAS. Additionally, with the account SAS, you can delegate access to operations that apply at the level of the service, such as Get/Set Service Properties and Get Service Stats operations. You can also delegate access to read, write, and delete operations on blob containers, tables, queues, and file shares that are not permitted with a service SAS.

3. What is an IL?

Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code is compiled to IL. IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.

4. What is code access security (CAS)?

Code access security (CAS) is part of the .NET security model that prevents unauthorized access of resources and operations, and restricts the code to perform particular tasks.

5. What is Difference between NameSpace and Assembly?

Assembly is physical grouping of logical units, Namespace, logically groups classes.

Namespace can span multiple assembly.

6. Mention the execution process for managed code.

A)Choosing a language compiler

B) Compiling the code to MSIL

C) Compiling MSIL to native code

D) Executing the code.

7. What is Microsoft Intermediate Language (MSIL)?

The .NET Framework is shipped with compilers of all .NET programming languages to develop programs. There are separate compilers for the Visual Basic, C#, and Visual C++ programming languages in .NET Framework. Each .NET compiler produces an intermediate code after compiling the source code. The intermediate code is common for all languages and is understandable only to .NET environment. This intermediate code is known as MSIL.

8. What is managed extensibility framework?

Managed extensibility framework (MEF) is a new library that is introduced as a part of .NET 4.0 and Silverlight 4. It helps in extending your application by providing greater reuse of applications and components. MEF provides a way for host application to consume external extensions without any configuration requirement.

9. Which method do you use to enforce garbage collection in .NET?

The System.GC.Collect() method.

10. What is the difference between int and int32.

There is no difference between int and int32. System.Int32 is a .NET Class and int is an alias name for System.Int32.

11. What are tuples?

Tuple is a fixed-size collection that can have elements of either same or different data types. Similar to arrays, a user must have to specify the size of a tuple at the time of declaration. Tuples are allowed to hold up from 1 to 8 elements and if there are more than 8 elements, then the 8th element can be defined as another tuple. Tuples can be specified as parameter or return type of a method.

12. What is the full form of ADO?

The full form of ADO is ActiveX Data Object.

13. What are the two fundamental objects in ADO.NET?

DataReader and DataSet are the two fundamental objects in ADO.NET

14. What is the meaning of object pooling?

Object pooling is a concept of storing a pool (group) of objects in memory that can be reused later as needed. Whenever, a new object is required to create, an object from the pool can be allocated for this request; thereby, minimizing the object creation. A pool can also refer to a group of connections and threads. Pooling, therefore, helps in minimizing the use of system resources, improves system scalability, and performance.

15. Mention the namespace that is used to include .NET Data Provider for SQL server in .NET code.

The System.Data.SqlClient namespace.

16. Which architecture does Datasets follow?

Datasets follow the disconnected data architecture.

17. What is the role of the DataSet object in ADO.NET?

One of the major component of ADO.NET is the DataSet object, which always remains disconnected from the database and reduces the load on the database.

18. Which property is used to check whether a DataReader is closed or opened?

The IsClosed property is used to check whether a DataReader is closed or opened. This property returns a true value if a Data Reader is closed, otherwise a false value is returned.

19. Name the method that needs to be invoked on the DataAdapter control to fill the generated DataSet with data?

The Fill() method is used to fill the dataset with data.

20. What are the pre-requisites for connection pooling?

There must be multiple processes to share the same connection describing the same parameters and security settings. The connection string must be identical.

21. Which adapter should you use, if you want to get the data from an Access database?

OleDbDataAdapter is used to get the data from an Access database.

22. What are different types of authentication techniques that are used in connection strings to connect .NET applications with Microsoft SQL Server?

The Windows Authentication option

The SQL Server Authentication option

23. What are the parameters that control most of connection pooling behaviors?

Connect Timeout

Max Pool Size

Min Pool Size

Pooling

24. What is AutoPostBack?

If you want a control to postback automatically when an event is raised, you need to set the AutoPostBack property of the control to True.