Newstechok.com

.Net core Interview questions and answers for Experienced And Freshers

Introduction

.NET Core is an open-source application and asp.net core training
cross-platform that runs on different operating systems such as Windows, Mac,
and Linux, to get designed and developed advanced cloud-based applications
including Web Apps, IoT apps, Mobile apps and Backends, and more. It is one of
the latest web development frameworks. like Node.JS, PHP, Java Servlet, and
Ruby on Rails.

1.  What is the ASP.NET Core?

Ans. ASP.NET Core
is not considered as an upgraded version of ASP.NET. ASP.NET Core rewrites
that perform with the .net Core framework. It is much quicker, configurable,
scalable, modular, and expandable, and has cross-platform assistance. It works
well with both the .net framework and .NET Core through the standard VB.NET
framework. The cloud-based web apps, mobile apps, and IoT apps could be well
developed through the .Net framework.

2. Q. What is MVC? Write its advantages.

Ans. MVC
stands for Model-View-Controller. .Net MVC renders a large set of extra
functionalities to develop modular applications that encapsulate business
logic and its implementation. It makes the entire application creation
procedure easy by rendering the dynamic websites or component-based program
development and testing.

It delivers advanced web standards and various features like routing, model
binding and validation, filters, razor view engine,
dependency injection, web APIs, etc.

Model (decouple data): It illustrates the state of application/logic,
where the business logic and its implementation get encapsulated.

View(interface): It is liable for delivering the view using the user
interface.

Controller(logic): It controls user interaction, and regulates in
tandem with different components of the model and view.

Advantages

  • It renders complete control over HTML implementation.
  • It implements separation of concerns(SoC).
  • It reduced the complexity of large applications into smaller units by
    dividing the application into patterns of 3 components that are model, view,
    and control.
  • It renders test-driven development (TDD) strategy.
  • It helps in integration with Java platforms including JavaScript, JSON,
    jQuery, etc., easily.
  • It incorporates the latest advanced technology and supports the latest
    requirements.

3. What are the significant features of ASP.NET Core?Supports

Ans. Following are the significant features of ASP.NET Core.

  1. It has introduced Kestrel – a new, cross-platform and fast, web server. So,
    a web application that is made of ASP.net core can run well without IIS,
    Nginx, and Apaand.
  2. It renders built-in assistance for Dependency Injection.
  3. It renders built-in assistance for the logging framework and it can be
    expandable well.
  4. It supports various hosting options. 
  5. Since, modularity is supported here, the developers include the appropriate
    module that needed by the application. Nevertheless, the .NET Core framework
    also renders the meta package that contains the libraries.
  6. Since, it has no web. config file, we can save the customized configuration
    into an appsettings.json file.
  7. Command-line supports to create, develop, and run the web application.
  8. Since, no Global.asax file is available, the developers can register now and
    utilize the services that are available in the startup class.
  9. It facilitates asynchronous programming more than a platform.
  10. It supports WebSocket and SignalR well.
  11. It protects against Cross-Site Request Forgery (CSRF).

4. What are the advantages of ASP.NET Core?

Ans. The following are the advantages of
ASP.NET Core
:

  1. Since it is cross-platform, it can run smoothly on Windows, Mac, and Linux.
  2. ASP.net core is not dependent on the installation of the framework because
    all the necessary dependencies are transported with our application.
  3. ASP.NET Core can manage more requests than ASP.NET.
  4. Different deployment options can be used in ASP.NET Core.

5. Find the difference between the .Net core and .Net framework.

Ans. Following are the differences between the
.Net core and .Net framework.

  1. .Net core is an open-source platform whereas the .Net framework’s few
    components are considered open-source.
  2. .Net core is compatible well with windows, Linux, and mac operating systems.
  3. .Net framework is well compatible with the windows operating system only.
  4. .Net core doesn’t support the development of the desktop application.
  5. .Net framework supports the development of desktop and web applications.
  6. .Net core helps in the development of microservices.
  7. .Net framework doesn’t support the development of microservices.
  8. .Net core becomes lightweight for CLI (Command Line Interface).
  9. .Net framework becomes heavy for CLI (Command Line Interface).

6. What are Metapackages?

Ans. Metapackage in ASP.NET 2.0 carries all the valuable dependencies
that are mandatory for ASP.NET code. It enables the developers to develop
faster as we don’t need to include the single ASP.NET Core packages
separately. ASP.NET Core provides assembly ‘Microsoft.AspNetCore.All‘ as a
meta package.

Unlike the naming convention in NuGetpackage, Metapackages are referred to as
to NETStandard.Library“. By referring to a metapackage, you can access all
its child packages which have a reference to its respective dependent
packages.

7. Can the ASP.NET Core app performs with full .NET 4.x Framework?

Ans. Yes. ASP.NET core app performs the task perfectly with a full .NET
framework through the standard .NET library.

8. Define the startup class in ASP.NET core?

Ans. The startup class is the main entry point so, every .NET Core app
must contain this class. The startup class carries the items that are related
to application configuration. It is not mandatory that the class must be named
as “startup” and also, its name can be anything. In the Program class, we can
configure the startup class with a customized name that is relevant to the
project name.

Example:

In the following example, ‘TC‘ is the startup class here.

9. Write is the utilization of the ConfigureServices method of the startup
class?

Ans. The ConfigureServices method is considered as an
elective method of the startup class. It helps to configure such services that
are utilized by the application. Through this method, the services can be
added to the DI container and services are accessible as a dependency within
the controller constructor. When the application gets requested for the first
time the ConfigureServices method calls first .

10. What is the importance of the Configure method of the startup class?

Ans. The configure method explains how the application responds to
every HTTP request.  The request pipeline can be configured well by
getting the middleware configured. It receives IApplicationBuilder as a
parameter and also it contains 2 optional parameters such as ILoggerFactory,
and IHostingEnvironment. The built-in middleware like routing, session,
authentication, etc., and 3rd-party middleware can be configured well using
this method.

11. What is middleware?

Ans. The middleware is a software, which is injected into the
application pipeline to control requests and responses. These are connected
like a chain and form a pipeline. However, the incoming requests pass through
this pipeline where the whole middleware is configured, and the middleware
will be able to perform some specific actions on the request before passing
the same request to the next middleware. In case of responses, they also pass
through the middleware reversely.

12. Give some examples of middleware.

Ans. In ASP.NET Core framework, huge numbers of components of built-in
Middleware  are available which can be used directly to act as components
of plug and play. If we aren’t interested to utilize the in-built middleware,
we can also create customized components of Middleware in asp.net core apps
whenever we wish. The most significant point that you desire to keep in mind
is, that in ASP.NET Core a given Middleware component needs to possess only a
particular objective which means it should be utilized for a unique
responsibility.

13. Differentiate IApplicationBuilder.Run() from IApplicationBuilder.Use()?

Ans. The above two methods in Configure methods of the specific
‘startup class’ can be used. Also, both help add middleware delegates to the
application request pipeline.

But, the difference is that the middleware adds utilizing
IApplicationBuilder.Use()’ calls the next middleware in the pipeline whereas
the middleware adds through ‘IApplicationBuilder.run()’ method never calls the
successive middleware. After ‘IApplicationBuilder.Run()’ method, system quits
adding middleware within the request pipeline.

14. What is the advantage of the “Map” extension while adding middleware to
the ASP.NET Core pipeline?

Ans. The ‘Map‘ extension is utilized for the pipeline branching.
It makes a branch of the ASP.NET Core pipeline according to the request path
matching. If the request path begins with the provided path, middleware on
that specific branch will perform.

15. What is routing in ASP.NET Core?

Ans. Routing is an important functionality ASP.Net core that helps in
mapping the incoming request to the route controller. The route can get values
that are extracted from the URL and these values are utilized to get the
request processed. Throughout the use of the route, routing can obtain a route
controller as per the URL. However, all the routes get registered when the
application gets started.


Mainly two types of routing are supported by ASP.NET Core.

  1. Conventional routing
  2. Attribute routing

Mostly, the application includes a single collection of routes which is
utilized for the processing of the request. Here, the RouteAsync method is
utilized to map incoming requests (which matches the URL) with availability in
route collection.

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

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

17. Write the name of various JSON files available in ASP.NET Core?

Ans. Following JSON files are available in ASP.NET Core

  1. global.json
  2. appsettings.json
  3. launchsettings.json
  4. bundleconfig.json
  5. bower.json
  6. package.json

18. What is tag helper in ASP.NET Core?

Ans. Tag helper‘ is a specific feature given by the ‘Razor view
engine’ that allows us to write server-side code to build and provide the HTML
element in razor view. The tag-helper is nothing but a C# class that is
incorporated to produce the view by joining the HTML element. The tag helper
functions like the HTML helper that belongs to ASP.NET MVC.

Example:

19. How to disable Tag Helper at the element level?

Ans. We can disable Tag Helper at the element level using the opt-out
character (“!”). This character must apply to open and close the Html tag.

Example

20. What are Razor Pages in ASP.NET Core?

Ans. In ASP.NET Core 2.0, Rajor pages follow a page-centric web
development model just similar to the web forms of ASP.NET. It supports all
the characteristics of ASP.NET Core.

Example

The Razor pages begin with the @page directive and this directive controls
requests directly and doesn’t pass through the controller. The Razor pages may
possess code-behind files, but it is not really a code-behind file. It is a
class inherited from PageModel class.

21. How can we bind the automatic model in Razor pages?

Ans. The Razor pages facilitate the required option to bind property
automatically while posting the data utilizing the ‘BindProperty‘ attribute.
It only binds the property with the non-GET verbs. Hence, we have to set
SupportsGet property to true to get a property bound on receiving a request.

Example

22. How can we inject the service dependency into the controller?

Ans.  Following are 3 easy steps to include a custom service
as a specific dependency on the controller.

Step 1: Create the service

Step 2: 

Add the above service now to the Service container (the above service can
either be incorporated by singleton, or transient, or scoped)

Step 3: 

Get this service used as a dependency in the controller.

23. How to determine the service life for a registered service that is
incorporated as a dependency?

Ans. ASP.NET Core enables us to mention the lifetime for the services
that are registered. The service specimen disposes automatically as per a
particular lifetime. So, no need to clean these dependencies, it takes care of
the ASP.NET Core Core.

—————————

24. How many types of life times are there?

Ans. Mainly 3 types of lifetimes are there.

i) Singleton

ASP.NET Core creates and shares a single unique specimen of the service
through the application lifetime. The service will be added as a singleton
through the ‘AddSingleton’ method of IServiceCollection. ASP.NET Core develops
a specific service specimen at the   registration time and
subsequence requests utilize this service specimen. Here, we shouldn’t execute
the Singleton design structure and single specimen retained by the ASP.NET
Core itself.

Example

ii) Transient

ASP.NET Core creates and shares a specimen of the service to the app when we
want it. We can add service as Transient through the AddTransient procedure of
IServiceCollection. Also, this lifetime is incorporated in a stateless
service. It is an approach to get the lightweight service added.

Example

iii) Scoped

In this lifetime, ASP.NET Core creates and shares a specimen of the service
per request to the particular application. A single specimen of service is
available per each request and it creates a new instance per each new request.

The service can be included as scoped utilizing an AddScoped method which
belongs to IServiceCollection. We should take care while the service
registered through Scoped in middleware and insert the service into the
methods of Invoke or InvokeAsync . If we inject dependency through the
constructor, it functions like a singleton object.

Example:

25. Explain Docker in .Net core.

Ans. Docker is an open platform for development, and execution of
applications. It facilitates you to isolate your applications quickly from the
infrastructure to communicate software. This feature is leveraged for
controlling infrastructure and deploying codes rapidly. It helps to decrease
the time required between writing and running codes in program infrastructure.

main functions:

  • Faster and continuous delivery of applications.
  • Run multiple workloads efficiently on the same hardware.
  • Helps in Responsive deployment quickly and scaling.

 Following points need to be taken care of while utilizing Docker in .NET
Core

  • You can utilize the CLI of the Docker client for handling images as well as
    containers.
  • You must integrate Docker containers, images, and registries adequately at
    the time of designing and containerizing apps or microservices.
  • Use Dockerfile for refurbishing images and allocate them with others.

26. What is .Net core CLI? Write name of its components.

Ans. .NET Core CLI is an important part of .NET SDK that delivers a
cross-platform toolset to develop, and run .NET Core apps. You will be able to
install multiple versions of the toolset on your pc.

Four types of commands

  • Basic commands help to develop web applications. Example – new,
    build, run, restore,  etc.
  • Project alteration commands enable you to utilize current packages or
    add packages to develop applications.
  • Advanced commands help conduct extra functions like deleting nuget.
  • Tool management commands can be used to control tools.

27. Describe Hosting environment management.

Ans. The ‘Hosting environment management’ of .NET Core,
allows you to function with various environments without friction. You can
utilize this characteristic through the interface, Hosting Environment. This
interface has been available since the initial running of the application. Its
execution depends on the variable of the environment and gets switched between
the configuration files at runtime.

This interface reads a particular environment variable that is named as
ASPNETCORE_ENVIRONMENT” and gets its value checked. Check its following
values:

  • If the value is ‘Development‘ – the application is running in Dev mode
  • If the value is ‘Staging‘ – the application is running in staging mode

This feature allows you to handle the various environments as well.

28. What is Garbage collection and write its benefits and conditions.

Ans. Garbage collection is another significant characteristic of
.NET Core. The basic function of this characteristic is to handle memory
allocation and delivery. The .NET Core possesses “Zero Garbage Collector” to
perform this function. This is called as Automatic Memory Manager.

Advantages:

  • No need to impose effort to release memory manually
  • Keeps the memory secured by making sure the usage of the object
  • Valuable object allotment on the heap
  • You can reclaim objects which are no longer required, keep the memory free,
    and utilize it for different purposes.

Following are 3 conditions that permit garbage collection.

  • The system retains low physical memory.
  • In case of an a favorable threshold.
  • The time of calling the Garbage Collection procedure.

29. What are CTS types in .NET Core?

Ans. CTS (Common Type System) standard defines and
expresses how to utilize data categories in the .NET framework. The
System.Object” is the base cts type which originates other categories in the
solely rooted object structure. It is a gathering of data categories, and
Runtime utilizes it to carry out the integration of cross-language.

CTS types can be categorized into two types:

Value types: This data type utilizes the real value of an object to
depict any object. If you nominate an instance of value type to a new
variable, that variable is provided a new copy of the value.

Examples: Built-in value types, Enumeration, User-defined value types,
Structure

Reference types: This data type utilizes a reference to the value of
object to depict the objects. You can state that it follows the theory of
pointers. It never creates any copy if you allocate a reference category to a
variable which further points to actual values.

Examples: Self-defining types such as array, interface Type,  and
pointer type.

30. Explain CoreRT.

Ans. CoreRT has been utilized in .NET Core as a native
toolchain which performs collection to translation. It means, coreRT compiles
the CIL code to machine code. The CoreRT utilizes RyuJIT for compilation,
which can be utilized with other compilers to execute native compilation for
UWP apps.

Benefits for developers

  • It is easier to work with a single file produced at the time of compilation
    along with the app, CoreRT, and well-handled dependencies.
  • Since it utilizes an optimized compiler, thus it produces faster outcomes
    from higher quality code.
  • It functions faster because of the previous performance of compiled code.
    You don’t have to produce machine code or get the JIT compiler loaded during
    runtime.

31. What is state management?

Ans. State management is a type of state control object to handle
the states of the object at the time of various procedures. Since HTTP, a
stateless protocol has been utilized, which is incapable to conserve user
values; so, various procedures have been utilized to store and retain the user
information between requests.

32. How to handle errors in .NET Core?

Ans. Following four methods are mainly used to handle errors in
.NET Core for specific web APIs.

  • Developer Exception Page
  • Exception Handler Page
  • UseStatusCodePages
  • Exception Handle Lambda

Among the above four methods, the best method is “Developer Exception Page” as
it shows detailed information including stacks, headers, query string
parameters, cookies about uncontrolled request exceptions. This page can be
easily enabled by running applications in the environment of development. This
page runs ahead in the middleware pipeline, so you could easily grab the error
in middleware.

33. Is MEF library still available in.NET core?

Ans. Yes, MEF (Managed Extensibility Framework) library is
still available and this library plays a significant role in building
lightweight and expandable applications. You can utilize extensions without
configuration easily. The extensions could be restored anywhere either inside
or outside the application. You will be able to perform code encapsulation and
restrict fragile complicated dependencies.

Even though it has become outdated but is still usable. In case you wish to
utilize it, you have to use it through some namespaces and plugins systems
like “System.Composition“, “Microsoft.Composition” and
System.ComponnetModel.Composition”.

34. Write about generic host in .NET core?

Ans. Previously, the generic host was called as ‘Web Host’, in
.NET Core for web apps. Afterward, the ‘Web Host’ was deprived and a generic
host was inducted to fulfill the need of web, Linux, and console apps.


Whenever a new app is commenced we need to take care of the following points:

  • Dependency Injection
  • Logging
  • Configuration
  • Service lifetime management

.NET generic host named ‘HostBuilder’ supports us to handle all the above
tasks since it is developed on the actual abstraction of the above tools.

35. What is role of IIS manager for ASP.NET MVC?

Ans.  ASP.NET MVC application
deployment procedure needs a windows server with an  IIS manager that is
installed. What you have to do is to utilize the
IIS manager
to conduct deployment after the development of the required applications. You
will be unable to publish any application to the public market without
deployment; thus, the IIS manager plays a basic role in finalizing this
procedure.

 Another deployment process is conducted using the Docker environment,
which in the beginning starts deploying the docker package on any server
machine and then carries out the successive deployment stage.

36. Describe role-based authentication in ASP.NET MVC.

Ans. Roles define the approval to get something accessed as well
as used. A user will be able to access any resource if they possess
authorization for that user. Hence, the Role-based authentication is mandatory
to confirm the security of applications and their respective information. It
distinguishes the role of providers and appropriate membership. The main
responsibility of providers is to approve and assign roles to users to make
sure proper authentication and flawless authorization.

37. Q. Describe the feature of ASP.NET core MVC to expose server-side code
which renders HTML elements.

Ans. ASP.NET Core
MVC
has new “Tag helper” feature that enables expose server-side code to render
HTML elements. Like “HTML Razor helpers, ” ‘Tag helper’ looks like basic HTML
elements. Don’t switch context between Razor and HTML Syntax. Tag helpers are
such objects, that you can combine them with the models and dynamically
provide HTML elements as per their properties.

Some genuine Tag-helper objects are given below

  • asp-action – helps to utilize action procedure
  • asp-route-id – helps To utilize route expression
  • asp-for – helps To utilize model binding
  • •sp-validation-summary – is used For validations

This feature helps the front-end designer at the time of working on JS,
CSS,  frameworks or libraries to update or alter the “View” without
learning the programming language. Further, they are durable and reusable,
which could be utilized in multiple views.

38. Q. Write about view component feature.

Ans. View Component is another advanced feature of ASP.NET core
MVC that is used for partial views. It is utilized for resolving multiple
issues. Its basic function is splitting the complicated views into reusable
fractions. The partial views help access the view model of parent page.

But, one deficiency of this feature is that it is unable to access the page
model and can function on the passed arguments only. Hence, the best utility
of this feature is to utilize it to provide reliable pieces of pages that
might contain logic. This feature can be utilized through dependency
injection, which enables it robust and reliable.

39. Describe the life cycle of MVC application

Ans. The
MVC application
life cycle includes two stages of implementing applications.

1st stage: Creating the request object

  • Fill in the route table through the collection of route
  • Fetch the route to make object “RouteData
  • Now utilize this object to make object “RequestContext
  • At the end, build a controller instance to regulate the class instance

2nd stage: Creation of the response object

  • Perform the action
  • Release the response to the web browser as a result

40. Write the difference between .Net core and. Mono.

Ans.  .Net core is a part of.NET framework that is
optimized specially for designing advanced apps and endorsing developer
workflows

Mono is also an important part of the .NET family frameworks, but this
framework is optimized for iOS, Android, Mac OS, and Windows devices through
the Xamarin platform.

Best Application area

. Net core is used to design command line apps, background service
apps, development of web and windows application

Mono is used for the development of a Mobile app, Designing games,
compilation of code within the web browser, designing and developing
multi-platform desktop apps.

Special features

.Net core is used for Natural acquisition, possesses a modular
framework, and smaller size deployment evidence, and quick release cycles.

Mono is used as a Native User Interface, Native API Access, Native
Performance, and Productivity.

App Models

.Net core has app models like UWP (Universal Windows Platform), and
ASP.NET Core.

Mono has Xamarin Android, Xamarin iOS, Xamarin Forms, and Xamarin Mac.

Base library

.Net core has CoreFX Class Library.

Mono has Mono Class Library

41. Describe Scaffolding in ASP.NET MVC.

Ans. Scaffolding helps developers generate code to conduct basic
functions like Create, Read, Edit, and Delete. You can change the codes as per
requirements. That’s why, it is called as a “code-generation framework” for
designing and developing
MVC apps. It assists improve the code which conducts data interaction of
applications. It also helps decrease the development time to implement data
operations.

Further, the framework includes multiple templates such as page templates,
entity page templates, field templates, and filter templates. These are also
called as Scaffold templates and these templates allow you to design and
develop a completely functional website.

42. What is role of action filters?

Ans. The prominent role of action
Filters in the ASP.NET MVC is the performance of filtering logic after an action
procedure is called. You will be able to call these filters to “custom
attributes” which assists to illustrate proclamations of pre or post-action
behavior to the action methods of the controller. These given attributes are
obtained from the “System.Attribute” that could be connected to classes,
fields, methods, or properties.

Following are some filter types, from which you can use anyone to conduct
filtering.

OutputCache filter grabs the output of a controller function for a
particular period.

HandleError filter manages errors that are raised during the execution
of a controller action.

Authorize Filter helps you to prohibit access to a a specific user or
role.

43. How to stop exceptions through ASP.NET MVC?

Ans. Restricting exception is a crucial part of the development
and execution of application. The error handling job is to concede to
exceptional ailments. ASP.NET MVC has various methods to stop exceptions,
including following


  • HandleErrorAttribute
    on controllers and effort procedure, controls errors
    and exception
  • Overriding OnException procedure is a void procedure that gets an argument
    as a particular object of ExceptionContext to control exception
  • TCF (Try-Catch-Finally) is combination of 3 blocks to take hold of the
    exception
  • Making a goal exception controlling filter method takes care of
    HandleErrorAttribute and you have to add it RegisterGlobalFilters.
  • Expanding HandleErrorAttribute, grants you to make your Exception Handler to
    handle the errors.

44. Write the difference between ViewBag and ViewData in ASP.NET MVC?

Ans. In ASP.NET MVC,  both ViewBag and ViewData are used for
transporting information from the controller to view.

Following are some differences between them:

Definition

ViewData is a type of dictionary object of the particular ‘ViewDataDictionary’
class retaining key-value.

ViewBag wraps around ViewData and is considered as a dynamic property.

Speed

ViewData is Faster than ViewBag

ViewBag is slower than ViewData.

Conversion code

For ViewData, Type conversion code is desired.

For ViewBag, Dynamic type conversion code is unnecessary.

45. How does the request flow in the ASP.Net MVC framework?

Ans. The request flows through the following two stages in the MVC
framework:

  • Routing step matches the style of the request’s URL against the targeted URL
    that is available in the route table.
  • MvcHandler begins the processing of the request through the ProcessRequest
    procedure.
  • Controller utilizes ‘IControllerFactory’ instance and then calls the
    ‘Execute’ procedure, where ‘IControllerFactory’ is known as a default
    controller factory or a customized factory can be explained.
  • Action execution is conducted after the occurrence of controller instance,
    ‘ActionInvoker’ defines which specific action needs to be executed on the
    controller.
  • View result:  In this step, the ‘action’ procedure keeps the response
    ready and then returns the required result.
  • View engine has component ‘IViewInterface’ that chooses a view engine to
    generate the result.
  • View (display): ‘ViewResult’ returns and displays an HTML page on the web
    browser.

Conclusion

I hope the above questions and answers will definitely help you to achieve
success in your interview on ASP.NET Core topic. Make your interview easier
with sufficient knowledge



http://www.technologycrowds.com/2022/10/net-core-interview-questions-Answers-For-Expereinced-Freshers.html

Exit mobile version