AWS Security Model

ASP.NET Core (.Net 6) Interview Questions and Answers for 2022

 Q1) What are the features provided by ASP.NET Core?

  • Built-in supports for the logging framework and it can be extensible
  • Built-in supports for Dependency Injection
  • Introduced new, fast and cross-platform web server - Kestrel. So, a web application can run without IIS, Apache, and Nginx.
  • Multiple hosting ways are supported
  • It supports modularity, so the developer needs to include the module required by the application. However, .NET Core framework is also providing the meta-package that includes the libraries
  • Command-line supports to create, build and run the application
  • There is no web.config file. We can store the custom configuration into an appsettings.json file
  • There is no Global.asax file. We can now register and use the services in startup class
  • It has good support for asynchronous programming
  • Support WebSocket and SignalR
  • Provide protection against CSRF (Cross-Site Request Forgery)

Q2) What are the advantages of ASP.NET Core over ASP.NET?

There are the 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 requests than the ASP.NET
  • Multiple deployment options are available withASP.NET Core

Q3) What is Metapackages?

  • The framework .NET Core 2.0 introduced Metapackage that includes all the supported packages by ASP.NET code 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 provided by ASP.NET core.

Q4) 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.

Q5) What is the startup class in ASP.NET core?

This class is described by its name: startup. It is the entry point of the application. It configures the request pipeline which handles all requests made to the application. The inception of startup class is in OWIN (Open Web Interface for.NET) application that is specification to reduce dependency of application on server.

public class Startup
{
    public void Configure(IApplicationBuilder app)
    {

    }
    public void ConfigureServices(IServiceCollection services)
    {

    }
}

Q6) What is the use of ConfigureServices method of startup class?

  • This is an optional 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.
  • Using this method, we can add the services to the DI container, so services are available as a dependency in controller constructor.

Q7) What is the use of the Configure method of startup class?

It defines how the application will respond to each HTTP request. We can 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.

Q8) What is middleware?

  • It is software which is injected into the application pipeline to handle requests and responses.
  • They are just like chained to each other and form as a pipeline.
  • The incoming requests are passed through this pipeline where all middleware is configured, and middleware can perform some action on the request before passing it to the next middleware. Same as for the responses, they are also passing through the middleware but in reverse order.

Q9) 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.

Q10) 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);
}

Q11) What is Host in ASP.NET Core?

Host encapsulates all the resources for the app. On startup, ASP.NET Core application creates the host. The Resources which are encapsulated by the host include:
  • HTTP Server implementation
  • Dependency Injection
  • Configuration
  • Logging
  • Middleware components

Q12) What is routing in ASP.NET Core?

Routing is functionality that map incoming request to the route handler.
The route can have values (extract them from URL) that used to process the request.
  1. Conventional routing
  2. Attribute routing

Q13) How to enable Session in ASP.NET Core?

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

Q14) What are the various JSON files available in ASP.NET Core?

  • global.json
  • launchsettings.json
  • appsettings.json
  • bundleconfig.json
  • bower.json
  • package.json

Q15) What is difference between Hashtable and Dictionary in C#  

Dictionary

  • Dictionary is generic type Dictionary<TKey,TValue>
  • Dictionary class is a strong type < TKey,TValue > Hence, you must specify the data types for key and value.
  • There is no need of boxing/unboxing.
  • When you try to access non existing key dictionary, it gives runtime error.
  • Dictionary maintains an order of the stored values.
  • There is no need of boxing/unboxing, so it is faster than Hashtable.

Example.

Dictionary<string, string> EmployeeList = new Dictionary<string, string>(); 
EmployeeList.Add("Mahesh Chand", "Programmer");             

Hashtable

  • Hashtable is non-generic type.
  • Hashtable is a weakly typed data structure, so you can add keys and values of any object type.
  • Values need to have boxing/unboxing.
  • When you try to access non existing key Hashtable, it gives null values.
  • Hashtable never maintains an order of the stored values.
  • Hashtable needs boxing/unboxing, so it is slower than Dictionary.

Example.

Hashtable HT = new Hashtable();   
HT.Add(1,"s");

I hope this is helpful to you☺

Comments