Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Core Interview

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1. What is .NET Core?

Asp.NET Core is a newer version of .NET, which is cross-


platform, supporting Windows, MacOS and Linux, and can be
used in device, cloud, and embedded/IoT scenarios.
2. What is Kestrel ?
Kestrel is a cross-platform web server built for ASP.NET
Core. . It is based on asynchronous I/O library called "libuv"
primarily developed for Node.js
It is default web server, but you still can use IIS, Apache,
Nginx etc.
3. Main characterestics of ASP.NET Core?
Here are the Top 10 Asp.Net Core features
o Cross-Platform webserver "Kestrel" & Container Support
o Single programming model for MVC and Web API
o Dependency Injection is heavily used in asp.net core
framework, We can extend it with other popular DI
containers
o We have built-in and extensible structured logging in
Asp.Net Core, also can use third party logging utility
o "WWWROOT" folder for static files
o fully async pipeline easily configured via middleware
o Razor page, specially designed for small size application,
supports cross platform deployment
o Provide protection against CSRF (Cross-Site Request
Forgery)
o Support WebSocket and SignalR
o Command-line supports to create, build, run an
application
o Tags Helpers in Asp.net Core helps in rapid Development.
o There is no web.config, We now use appsettings.json file
to store configuration information
o There is no Global.asax, We have Startup.cs, to setup
new Middleware and services for DI Container.
4. Where to keep configuration information in asp.net
core.
Now there is no web.config file, in Asp.net core we have to
store configuration information in  asppsettings.json file,
which is plain text file, keep information as key-value pair in
json format .
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
//"Default": "Warning"
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"DbConnectionConfig": {
"DatabaseName": "databaseName",
"UserName": "username",
"Password": "password",
"ServerName": "IP-Address"
}
}

5. What is Middleware in ASP.NET Core?


Middleware is software injected into the application pipeline
to handle request and responses. Now we can manipulate
http request and response which was not possible with
earlier Asp.net Framework, Middleware are just like chained
to each other and form as a pipeline. We can change the
order in configuration
6. What is the startup class in ASP.NET core?
Startup class is the entry point of any ASP.NET Core
application, This class contains the application configuration
rated details, it has two main method ConfigureServices()
and Configure()
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMvc().AddRazorOptions(opt =>
{

opt.PageViewLocationFormats.Add("/Pages/shared/{0}.csht
ml");
});
}
public void Configure(IApplicationBuilder app,
IHostingEnvironment env, ILoggerFactory loggerFactory)
{
}
}

7. What are advantages of ASP.NET Core compare to


ASP.NET?
Here are the key advantages of using Asp.Net Core
o It supports cross-platform application building, so it can
be run on Windows, Linux and Mac.
o Now no framework installation required, because all the
required dependencies are packaged with asp.net core
application
o Asp.Net Core has in-built logging capabilities
o ASP.NET Core can handle request more efficiently than
the ASP.NET
8. What is Configure method of startup class, what does it
do?
It defines the HTTP pipeline, how the application will
respond to request. We can change the sequence of
middleware configuration, it accepts IApplicationBuilder as a
parameter and two optional parameters:
IHostingEnvironment and ILoggerFactory.

Using this method, we can configure built-in middleware


such as authentication, error handling and also any custom
middleware or third-party middleware.
9. Difference between IApplicationBuilder.Use() and
IApplicationBuilder.Run()?
Both methods are used to add middleware delegate to the
application request pipeline.

Use method may call the next middleware in the pipeline.


Run method never calls the subsequent ore next middleware,
After IApplicationBuilder.Run method, system stops adding
middleware in pipeline
10. Explain routing in ASP.NET Core?
Routing is the functionality that map incoming request to the
route handler. There are two type of routing supported by
ASP.NET Core
o Conventional routing
o Attribute routing
11. How to enable Session in ASP.NET Core?
The middleware for the session is provided by
Microsoft.AspNetCore.Session. To use the session in ASP.NET
Core application we need to add the middleware in pipeline

public class Startup


{
public void ConfigureServices(IServiceCollection
services)
{
services.AddSession();
services.AddMvc();
}
public void Configure(IApplicationBuilder app,
IHostingEnvironment env)
{
app.UseSession();
}
}

12. What are the different JSON files available in


ASP.NET Core?
o appsettings.json
o bundleconfig.json
o global.json
o npm-shrinkwrap.json
o launchsettings.json
o bower.json
o package.json
13. How automatic model binding in Razor pages works?
When we create a razor page, it provides the option to have
model binging or not, in model binding there is a model
created with the razor page, the model is inherited from  :
PageModel we need to use [BindProperty] attribute to bind
any property to model

Here is an example
public class ContactModel : PageModel
{
[BindProperty]
public string StudentName { get; set; }
}

14. What is the use "Configure" method of startup


class?
In "Configure" method we can define each HTTP request and
how they will respond in application. In "Configure" method
there is IApplicationBuilder parameter
public void Configure(IApplicationBuilder app,
IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseStaticFiles();
app.UseIdentity();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template:
"{controller=Home}/{action=Index}/{id?}");
});
}

There are two other parameters IHostingEnvironment and


ILoggerFactory, Even we can define different pipeline for
different development environment
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}

We also can configure third-party middleware.


15. What is Metapackage in Asp.Net Core?
In ASP.NET Core project we don’t need to include individual
package references in the .csproj file. There is one file
called “Microsoft.AspNetCore.All” is added under NuGet, now
“Microsoft.AspNetCore.All” contains all the required
packages. That’s the concept of metapackage, you can check
all files added under that package by expanding following
file in your project solution, “Dependencies” => “NuGet” =>
“Microsoft.AspNetCore.All”
16. What is Microservices in Asp.Net Core?
Microservices are type of API service, that are small,
modular, can be deployed independently, which can run in an
isolated environment. Read more about  Microservices Design
Principal

You might also like