You are on page 1of 16

Dot Net Core 3.0, 3.

1 And MS Azure Interview Questions

1. What is middleware?
It is a software component that is assembled into the application pipeline to handle the HTTP
Request and Response. Each middleware component perform the task
1. to pass the HTTP Request to the next component in the pipeline. This can be
achieved by calling the next() method within the middleware.
Can perform work before and after the next component in the pipeline.
Thare are so many build-in middleware components available in .net core that can be use
directly.
Middlware can be configured in configure() method of startup class. This is the class that is
going to run when the application starts.

2. What is the Execution Order of Middleware Components in ASP.NET Core Application?


The ASP.NET Core middleware components are executed in the same order as they are added
to the pipeline

3. Where we use Middleware Components in the ASP.NET Core application? -extra

1. We may have a Middleware component for authenticating the user


2. Another Middleware component may be used to log the request and response
3. Similarly, we may have a Middleware component that is used to handle the errors
4. We may have a Middleware component that is used to handle the static files such as
images, Javascript or CSS files, etc.
5. Another Middleware component may be used to Authorize the users while accessing a
specific resource

4. How to configure middleware in Asp.net core application.-extra


Middleware is configure in configure() method of Startup.cs class by calling the Use* methods
on the IApplicationBuilder object. This is the class that is going to run when the application
starts.
the Configure() method sets up the request processing pipeline with just three middleware
components are as follows.
1. UseDeveloperExceptionPage() Middleware component
2. UseRouting() Middleware component
3. UseEndpoints() Middleware component

5. What are the advantages of ASP.NET Core over ASP.NET?


There are following advantages of ASP.NET Core over ASP.NET :
 It is cross-platform, so it can be run on Windows, Linux, and Mac.
 There is no dependency on framework installation because all the required dependencies are ship
with our application
 ASP.NET Core can handle more request than the ASP.NET
 Multiple deployment options available withASP.NET Core
 We can host the earlier ASP.NET Framework 4.x applications only on IIS whereas we can host
the ASP.NET Core applications on IIS, Nginx, Docker, Apache, or even self-host deployment.

6. What is the startup class in ASP.NET core?


Startup class is the entry point of the ASP.NET Core application. Every .NET Core application
must have this class. This class contains the application configuration related items. It is not
necessary that class name must "Startup", it can be anything, The startup class can be
configured using UseStartup<T>() extension method at the time of configuring the host in the
Main() method of Program class.

public class Program

public static void Main(string[] args)

{
CreateWebHostBuilder(args).Build().Run();

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>

WebHost.CreateDefaultBuilder(args)

.UseStartup<TestClass>();

7. What is the use of ConfigureServices method of startup class?


It can be used to configure the services that are used by the application. This method
calls first when the application is requested for the first time
The ConfigureServices method is a place where you can register your dependent classes
with the built-in IoC container. After registering the dependent class, it can be used
anywhere in the application. You just need to include it in the parameter to the
constructor of a class where you want to use it.

8. What is the use of the Configure method of startup class?


It defines how the application will respond to each HTTP request. It is used to configure
the request pipeline by configuring the middleware. It accepts IApplicationBuilder as a
parameter and also it has two optional parameters: IHostingEnvironment and
ILoggerFactory. Using this method, we can configure built-in middleware such as
routing, authentication, session, etc. as well as third-party middleware.

In current project we used/Register below middleware in configure class.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)


{
app.UseForwardedHeaders();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseCors(c =>
{
c.AllowAnyOrigin();
c.AllowAnyHeader();
c.AllowAnyMethod();
});
}

app.UseRouting();

app.UseMiddleware<LoggingMiddleware>();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(c => c.MapControllers());

9. What are Request Delegates in ASP.NET Core?-extra

In ASP.NET Core, Request delegates are used to build the request pipeline i.e. request delegates
are used to handle each incoming HTTP request. In ASP.NET Core, you can configure the
Request delegates using the Run, Map, and Use extension methods.

10. What is the difference between IApplicationBuilder.Use() and


IApplicationBuilder.Run()?
We can use both the methods in Configure methods of startup class. Both are used to add
middleware delegate to the application request pipeline. The middleware adds using
IApplicationBuilder.Use may call the next middleware in the pipeline whereas the middleware
adds using IApplicationBuilder.Run method never calls the subsequent or next middleware.
After IApplicationBuilder.Run method, system stop adding middleware in request pipeline.

11. What is starting point in .Net Core App


The most important point is, the ASP.NET Core Web Application initially starts as a Console
Application and the Main () method is the entry point to the application. So, when we execute
the ASP.NET Core Web application, first it looks for the Main () method and this is the method
from where the execution starts.

12. What is routing in ASP.NET Core?


The Routing in ASP.NET Core MVC application is a mechanism in which it will inspect the
incoming Requests (i.e. URLs) and then mapped that request to the controllers and their action
methods. This mapping is done by the routing rules which are defined for the application. We
can do this by adding the Routing Middleware to the request processing pipeline.
There are 2 types of routing is used in Asp.net Core MVC :
 Conventional base Routing - In Conventional Based Routing, the route is determined
based on the conventions defined in the route templates which will map the incoming
Requests (i.e. URLs) to controllers and their action methods. In ASP.NET Core MVC
application, the Convention based Routes are defined within the Configure method of
the Startup.cs class file.
 Attribute base Routing - In Attribute-Based Routing, the route is determined based on
the attributes which are configured either at the controller level or at the action method
level. We can use both Conventional Based Routing and Attribute-Based Routing in a
single application.

13. what is Difference between MVC Routing and .Net core Routing mechanism
I asp.net MVC routing we can define conventional base routing in RouteConfig.cs class
which id define in App_Statup folder and in Asp.net core MVC routing template is define
configure method of Startup class. Use the middleware service to configure the
conventional base routing in .net core.

14. Explain how you implemented Authentication and Authorization in your project
In my current project we configure Authentication and authorize middleware in
configure class. In ConfigureServices method of Startup.cs. create an Authentication
Middleware Services with the AddAuthentication and AddCookie method.
Authentication scheme passed to AddAuthentication sets to the default authentication
scheme for the app. CookieAuthenticationDefaults.AuthenticationScheme provides
“Cookies” for the scheme. In AddCookie extension method, set the LoginPath property
of CookieAuthenticationOptions to “"/Login”. CookieAuthenticationOptions class is used
to configure the authentication provider options.

services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Login";
options.LogoutPath = "/Login/Logout";
options.AccessDeniedPath = "/";
});
In Configure method of Startup.cs, call UseAuthentication and UseAuthorization method before
calling the endpoints.
After clicking login button it will call the login controller and check input user name password
and expiry date if it is valid then login successfully and stored details in cookies else throw the
exception.

15. How to manage different environment setting files in .net core.

ASP.NET Core use environment variables to configure application behavior based on


runtime environment. launchSettings.json file
sets ASPNETCORE_ENVIRONMENT to Development on local Machine. For more
visit How to use multiple environments in ASP.NET Core

Use multiple environments in ASP.NET Core | Microsoft Docs

16. Describe the Dependency Injection.

Dependency Injection is a Design Pattern that's used as a technique to achieve the Inversion of
Control (IoC) between the classes and their dependencies.
ASP.NET Core comes with a built-in Dependency Injection framework that makes configured
services available throughout the application. You can configure the services inside the
ConfigureServices method as below.

services.AddScoped();
A Service can be resolved using constructor injection and DI framework is responsible
for the instance of this service at run time. For more visit ASP.NET Core Dependency
Injection
17. Describe the Service Lifetimes.

When Services are registered, there is a lifetime for every service. ASP.NET Core provide
following lifetimes.

ASP.NET Core allows to specify the lifetime for registered services. The service instance gets
disposed of automatically based on a specified lifetime. So, we do not care about the cleaning
these dependencies, it will take care by ASP.NET Core framework. There is three type of
lifetimes.

 Singleton: In this case, the IoC container will create and share a single instance of a
service object throughout the application’s lifetime.
 Transient: In this case, the IoC container will create a new instance of the specified
service type every time you ask for it.
 Scoped: In this case, the IoC container will create an instance of the specified service
type once per request and will be shared in a single request.

18. How to read appsetting.json value?

You can read values from appsettings.json using below code.

class Test{
// requires using Microsoft.Extensions.Configuration;
private readonly IConfiguration Configuration;
public TestModel(IConfiguration configuration)
{
Configuration = configuration;
}
// public void ReadValues(){
var val = Configuration["key"]; // reading direct key values
var name = Configuration["Employee:Name"]; // read complex values
}
}
Default configuration provider first load the values from appsettings.json and then from
appsettings.Environment.json file.
Environment specific values override the values from appsettings.json file. In development
environment appsettings.Development.json file values override the appsettings.json file
values, same apply to production environment.
You can also read the appsettings.json values using options pattern described Read values
from appsettings.json file.

19. Is it possible to create multiple startup class in .net core?

20. What is Metapackages?


The framework .NET Core 2.0 introduced Metapackage that includes all the supported package
by ASP.NET core with their dependencies into one package. It helps us to do fast development
as we don't require to include the individual ASP.NET Core packages. The assembly
Microsoft.AspNetCore. All is a meta package provide by ASP.NET core.

21. Can ASP.NET Core application work with full .NET 4.x Framework?
Yes. ASP.NET core application works with full .NET framework via the .NET standard library.

-------------------------------------------------------------

22. What is the use of "Map" extension while adding middleware to ASP.NET Core
pipeline?
It is used for branching the pipeline. It branches the ASP.NET Core pipeline based on request
path matching. If request path starts with the given path, middleware on to that branch will
execute.

public void Configure(IApplicationBuilder app)

app.Map("/path1", Middleware1);

app.Map("/path2", Middleware2);

23. How to enable Session in ASP.NET Core?


The middleware for the session is provided by the package Microsoft.AspNetCore.Session. To
use the session in ASP.NET Core application, we need to add this package to csproj file and add
the Session middleware to ASP.NET Core request pipeline.
public class Startup

public void ConfigureServices(IServiceCollection services)

….

….

services.AddSession();

services.AddMvc();

public void Configure(IApplicationBuilder app, IHostingEnvironment env)

….

….

app.UseSession();

….

….

24. What are the various JSON files available in ASP.NET Core?
There are following JSON files in ASP.NET Core :
 global.json
 launchsettings.json
 appsettings.json
 bundleconfig.json
 bower.json
 package.json
25. What is the purpose of the wwwroot folder in Asp.net Core?

The wwwroot folder contains all static files like CSS, Images, JavaScript, Html files which are
served directly to the clients.

Advantages of Tokens in Attribute Routing:


The main advantage is that in the future if you rename the controller’s name or the action
method name then you do not have to change the route templates. The application is going to
works with the new controller and action method names.

26. How to inject service Dependency into controller


Asp.net core inject object of dependency classes through constructor or method by using
build in loc container. To inject the loc container to our application service, first need to
register them with loC container.
Asp.net core allow us to register our application service with loC container, in the
ConfigureServices method of the Startup class.

27. How to Add Exception handling code in only one place?


app.UseDeveloperExceptionPage();

28. How to implement Custom middleware in .net core


1. Create custom middleware component So, let us add a new class file to our
project. It is this class file that is going to contain the logic. So, right-click on the
project name and then select add => class.
Note- in optimize verify we have added custom middleware for logging.
LoggingMiddleware.cs
2. In order to make class a middleware component, the class need to be inherited
from middleware interface. Further IMiddleware interface belongs to
Microsoft.AspNetCore.Http namespace. And we need to implement the InvokeAsync or
Invoke method. And you need to write your logic within the InvokeAsync method.

Note: While calling the next method from any custom middleware components, we need to
pass the context object

3. Inject the service to the built-in dependency injection container in ConfigureService()


method of starutp class.
services.AddTransient<LoggingMiddleware>();
4. Registering the Custom Middleware in the HTTP Request Processing Pipeline in
configure() method of Startup class.

What is the Zero Garbage Collectors?

Zero Garbage collectors is the simplest possible implementation that in fact does almost nothing. It
only allows you to allocate object because this is obviously required by the Execution Engine. Create
object are never automatically deleted and theoretically, no longer needed memory is never reclaimed.

29. What are the ways to secure Web Apis


30. How to improve Performance of your application (Multithreding, Async, await, Database side
performance management)

Varsha

What is the Layout view?

The layouts are like the master pages in Webforms applications. The common UI code, which can be
used in many views can go into a common view called layout.

What is _ViewImports.cshtml in ASP.NET Core MVC Application?


In ASP.NET Core MVC Application, the _ViewImports.cshtml file provides a mechanism to include the
directives globally for Razor Pages so that we don’t have to add them individually in each and every
page. As of this article, the _ViewImports.cshtml file supports the following directives:
1. @addTagHelper
2. @tagHelperPrefix
3. @removeTagHelper
4. @namespace
5. @inject
6. @model
7. @using

What are Tag Helpers in ASP.NET Core?


Tag Helpers in ASP.NET Core are the server-side components. They are basically used to perform defined
transformations on HTML Elements. As they are server-side components, so they are going to be
processed on the server to create and render HTML elements in the Razor files.

8. What are lifespans of Service how to Set that explain in detail with example-Azure
9. How you Monitor your Application Performance(Explain Azure App Insight )
10. How you Handled Exceptions in .net core(Explain Log file implementation and
Appinsights)
11. How you manage App security(Explain Azure Keyvault Service )

12. How you managed Data Masking in your application

13. Explain Entity Framework .net core

14. Which Approach you used in Entity framework

15. Explain Which pattern you used in your project and why
Azure Interview Question
1. Explain Azure Pricing structure
2. Which Azure Services you have used in your project
3. Explain what is Azure Keyvault how to implement it in our application
4. What is Application Insights and How to use it in our App
5. What is Azure Active directory Authentication
6. How Token generates in AAD Auth
7. Explain the flow from User request to response if we are using AAD app
8. How to create AAD App in Azure portal
9. How to manage Users
10. How to Implement Role Based authentication
11. Steps to implement AAD auth in Application
12. How to manage the Token at server side
13. In which file we need to add Keyvault configuration settings
14. What is Blob Storage why to use it
15. What is meant by PaaS, SaaS, and IaaS?
16. How to connect to Azure SQL Server

Repository design patter is abstraction layer between data access layer and business layer. a
repository is nothing but a class defined for an entity, with all the possible database operations.
For example, a repository for an Employee entity will have the basic CRUD operations and any
other possible operations related to the Employee entity.

What is the Thread?


Generally, a Thread is a lightweight process. In simple words, we can say that a Thread is a unit
of a process that is responsible for executing the application code. So, every program or
application has some logic or code and to execute that logic or code, Thread comes into the
picture.

every application is a single-threaded application.

What are the drawbacks of Single-Threaded Applications?

In a single thread application, all the logic or code present in the program will be executed by a
single thread only i.e. the Main thread. For example, if we have three methods in our
application and if all these three methods are going to be called from the Main method. Then
the main thread is responsible to execute all these three methods sequentially i.e. one by one.
It will execute the first method and once it completes the execution of the first method then
only it executes the second method and so on.
How to solve the single threaded application problem?

we are provided with a concept called Multithreading in C#.


The main advantage of using Multithreading is the maximum utilization of CPU resources. A
process can have multiple threads and each thread can perform a different task. In simple
words, we can say that the three methods we define in our program can be executed by three
different threads. The advantage is that the execution takes place simultaneously. So when
multiple threads trying to execute the application code, then the operating system allocates
some time period to each thread to execute.

What is a Callback Method in C#?


We can define a callback function as a function pointer that is being passed as an argument to
another function. And then it is expected to call back that function at some point in time.

Asynchronous Programming in C#
A task in C# is used to implement Task-based Asynchronous Programming and was introduced
with the .NET Framework 4. The Task object is typically executed asynchronously on a thread
pool thread rather than synchronously on the main thread of the application. A task scheduler
is responsible for starting the Task and also responsible for managing it.
Tasks in C# is nothing but an operation or a work that executes in asynchronous manner.
in-fact the Task Parallel Library which is known as TPL is based on the concept of Tasks.
n C# Task is basically used to implement asynchronous programming model, the .Net runtime
executes a Task object asynchronously on a separate thread from the thread pool.

Three different ways to create and start a task in C#

Task task1 = new Task(PrintCounter);


task1.Start();

Task task1 = Task.Factory.StartNew(PrintCounter);

Task task1 = Task.Run(() => { PrintCounter(); });


As we already discussed, the tasks will run asynchronously on the thread pool thread and the
thread will start the task execution asynchronously along with the main thread of the
application. So far the examples we discussed in this article, the child thread will continue its
execution until it finishes its task even after the completion of the main thread execution of the
application.
If you want to make the main thread execution wait until all child tasks are completed, then you
need to use the Wait method of the Task class. The Wait method of the Task class will block the
execution of other threads until the assigned task has completed its execution.

What is a Thread pool in C#?


A Thread pool in C# is a collection of threads that can be used to perform a number of tasks in
the background. Once a thread completes its task, then again it is sent to the thread pool, so
that it can be reused. This reusability of threads avoids an application to create a number of
threads which ultimately uses less memory consumption.

Cognizent
1. Difference between ActionResult and ViewResult

You might also like