ASP Dot Net Core Interview Questions

    1. Question 1. What Are The Advantages Of The Inclusion Of Nuget Packages In Asp.net Core 1.0?

      Answer :

      The inclusion of Nuget Packages will make the applications to be optimized as we need to include only those packages that we need. The benefits includes 

      • Better performance gain 
      • Secured Application 
      • Improved and reduced servicing 
      • Pay for what you use model 
      • Lightweight

    2. Question 2. What Is Asp.net Core 1.0?

      Answer :

      Asp.net Core1.0 is the next version of Asp.net which is 5.0. It is open source and cross-platform framework (supports for Windows, Mac and Linux) suitable for building cloud based internet connected applications like web apps, IoT apps and mobile apps.Asp.net Core has made itself independent of System.Web.dll and is heavily based on the modular NuGet packages.

    3. Question 3. What Is The Purpose Of Webhostbuilder() Function?

      Answer :

      It is use to build up the HTTP pipeline via webHostBuilder.Use() chaining it all together with WebHostBuilder.Build() by using the builder pattern. It is available within the Microsoft.AspNet.Hosting namespace.The purpose of the Build method is to build the required services and a Microsoft.AspNetCore.Hosting.IWebHost which hosts a web application.

    4. Question 4. What Is The Purpose Of Useiisintegration?

      Answer :

      UseIISIntegration configures the port and base path the server should listen on when running behind AspNetCoreModule. The app will also be configured to capture startup errors. WebHostBuilder uses the UseIISIntegration for hosting in IIS and IIS Express.

    5. Question 5. What Is The Purpose Of Configureservices In Asp.net Core 1.0?

      Answer :

      ConfigureServices defines the services used by the application like ASP.NET MVC Core framework, Entity Framework Core, CORS,Logging, MemoryCaching etc. 

      E.g. 

      public void ConfigureServices(IServiceCollection services)

      {

          // Add framework services.

      services.AddApplicationInsightsTelemetry(Configuration);

          services.AddMvc();            

      }

    6. Question 6. Explain The Purpose Of Configure Method?

      Answer :

      Configure method defines the middleware in the Http request pipeline. The software components that are assembled into an application pipeline to handle requests and responses are the middlewares. 

      E.g. 

      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

      {   loggerFactory.AddConsole(Configuration.GetSection("Logging"));

          loggerFactory.AddDebug();

          app.UseApplicationInsightsRequestTelemetry();

          if (env.IsDevelopment())

          {

            app.UseDeveloperExceptionPage();

              app.UseBrowserLink();

          }

          else

          {

              app.UseExceptionHandler("/Home/Error");

          }

          app.UseApplicationInsightsExceptionTelemetry();

          app.UseStaticFiles();

          app.UseMvc(routes =>

          {

              routes.MapRoute(

                  name: "default",

                  template: "{controller=Home}/{action=Index}/{id?}");

          });

      }

      In the above code,UseExceptionHandler is a middleware. It is added as a middleware to the pipeline that will catch exceptions, log them, reset the request path, and re-execute the request.

    7. Question 7. What Is The Purpose Of Usedeveloperexceptionpage()?

      Answer :

      This method belongs to the Microsoft.AspNetCore.Builder namespace of USEDeveloperExceptionPage Extensions static class. The purpose of this function is to capture synchronous and asynchronous System.Exception instances from the pipeline and generates HTML error responses. It returns a reference to the app after the operation is completed.We use the UseDeveloperException() extension method to render the exception during the development mode.

    8. Question 8. What Is The Purpose Of Addsingleton Method?

      Answer :

      The AddSingleton method, adds a singleton service of the type specified in TService with an implementation type specified in TImplementation to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection. It returns a reference to this instance after the operation has completed. 

      The general syntax is 

      public static IServiceCollection AddSingleton<TService, TImplementation>(this IServiceCollection services)

                  where TService : class

                  where TImplementation : class, TService;

      Services can be registered with the container in several ways.In this case we are using Singleton Service by using the AddSingleton<IService, Service>() method.Singleton lifetime services are created the first time they are requested and then every subsequent request will use the same instance. If the application requires singleton behavior, allowing the services container to manage the service's lifetime is recommended instead of implementing the singleton design pattern and managing the object's lifetime in the class. 

      e.g. 

      public void ConfigureServices(IServiceCollection services)

      {

          // Add framework services.           

          services.AddSingleton<IEmployeeRepository, EmployeeRepository>();

      }

    9. Question 9. What Is Transfer-encoding?

      Answer :

      The encoding used to transfer the entity to the user. It is set to Chunked indicating that Chunked transfer encoding data transfer mechanism of the Hypertext Transfer Protocol (HTTP) is initiated in which data is sent in a series of "chunks".

    10. Question 10. What Is X-sourcefiles?

      Answer :

      It is the custom header. It contains the base64-encoded path to the source file on disk and is used to link a page's generated output back to that source file. It's only generated for localhost requests.

    11. Question 11. How To Scaffold Model From Existing Database In Asp.net Mvc Core?

      Answer :

      To scaffold models from existing database in ASP.NET MVC Core, go to Tools –> NuGet Package Manager –> Package Manager Console 

      Now execute following command:

      Scaffold-DbContext "Server=datbase-PC;Database=TrainingDatabase;Trusted_Connection=True;MultipleActiveResultSets=true;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models 

      If you get an error "The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet" , simply Close the Visual Studio and open again. 

      This creates .cs files related with all database tables into Models folder of your project. This also creates a database context (in this case the name will be TrainingDatabaseContext.cs as the database name is TrainingDatabase).

    12. Question 12. What Is .net Core?

      Answer :

      • A cross-platform version of .NET, that supports almost all things that .NET supported (except things like WPF, Windows Forms, Web Forms and Active Directory)
      • It is leaner, faster and improved version of .NET
      • .NET Core and ASP.NET Core are FREE and Open Source but also they are supported by Microsoft.
      • It is kinda the new .NET framework
      • Main framework that Microsoft has been focusing on is .NET Core
      • The .NET Core Runtime installation file is only about 20 MBs
      • .NET Core provides dotnet CLI – command line interface

    13. Question 13. What Is Asp.net Core?

      Answer :

      ASP.NET Core is a brand new cross-platform web framework built with .NET Core framework.

      It is not an update to existing ASP.NET framework. It is a complete rewrite of the ASP.NET framework. It was built from scratch in the effort to make a modular, scalable, super fast, configurable, cross-platform and easily extended web framework.

      ASP.NET Core (on Linux!) itself can handle over 2 000 000 – 2 Million requests per second for plaintext request/response scenarios. ASP.NET Core MVC can handle over 1 million requests per second! Compared to Node.js, which can handle about 400 000 requests per second, this is an amazing effort.

      It works with both .NET Core and .NET Framework.

      ASP.NET Core is much cleaner and easier to work with. You only need to write 20~30 lines of code and you have the web server ready to run. It also works smoothly with your file system, so can just copy and paste files to your project folder. And no, you don’t need to reference these files from a .csproj file.

      Main characterestics of ASP.NET Core:

      • DI Container which is quite simple and built-in. You can extend it with other popular DI containers
      • Built-in and extensible structured logging. You can redirect output to as many sources as you want (file, Azure, AWS, console)
      • Extensible strongly typed configuration, which can also be used to reload at run-time
      • Kestrel – new, cross-platform and super fast web server which can stand alone without IIS, Nginx or Apache
      • New, fully async pipeline. It is easily configured via middleware
      • ASP.NET All meta package which improves development speed, and enables you to reference all Microsoft packages for ASP.NET Core and it will deploy only those that are being used by your code
      • There is no web.config. We now use appsettings.json file in combination with other sources of configuration (command line args, environment variables, etc.)
      • There is no Global.asax – We have Startup.cs which is used to set up Middleware and services for DI Container.

    14. Question 14. What Is .net Standard?

      Answer :

      • .NET Standard is a set of APIs that all .NET platforms have to implement. This unifies the .NET platforms and prevents future fragmentation.
      • .NET Standard 2.0 is implemented by .NET Framework, .NET Core, and Xamarin. For .NET Core, this added many of the existing APIs that have been requested.
      • .NET Standard 2.0 includes a compatibility shim for .NET Framework binaries, significantly increasing the set of libraries that you can reference from your .NET Standard libraries.
      • .NET Standard will replace Portable Class Libraries (PCLs) as the tooling story for building multi-platform .NET libraries.

    15. Question 15. Can Asp.net Core Work With The .net Framework?

      Answer :

      Yes. This might surprise many, but ASP.NET Core works with .NET framework and this is officially supported by Microsoft.

    16. Question 16. Dependency Injection In Asp.net Core?

      Answer :

      Dependency Injection comes as a part of ASP.NET Core Framework and everything is built around it. When you want to use some tool and its services, you usually add the NuGet package and you use one of its extension methods to add the package to the ASP.NET Core’s DI container. You can extend the current DI with a container of your choice (AutoFac, StructureMap, CastleWindsor etc).

    17. Question 17. The Configuration In Asp.net Core?

      Answer :

      Another crucial part of ASP.NET Core Framework is Configuration. Also, it is part of Dependency Injection. Use it anywhere in your code with an option to reload on changes of configuration values from sources (appsettings.json, environment variables, command line arguments, etc.). It is also easy to override, extend and customize the Configuration. No more extensive configurations in web.config, the preferred way now is appsettings.json in combination with a mix of Environment variables and cmd-line args.

    18. Question 18. Talk About Logging In Asp.net Core?

      Answer :

      Logging is built-in and you get access to structured logs from the ASP.NET Core host itself to your application. With tools like Serilog, you can extend your logging easily and save your logs to file, Azure, Amazon or any other output provider. You can configure verbosity and log levels via configuration (appsettings.json by default), and you can configure log levels by different categories.

    19. Question 19. Explain Startup Process In Asp.net Core?

      Answer :

      Everything starts from Program.cs

      public static void Main(string[] args)

      {

          BuildWebHost(args).Run();

      }

      public static IWebHost BuildWebHost(string[] args) =>

          WebHost.CreateDefaultBuilder(args)

              .UseStartup()

              .Build();

      CreateDefaultBuilder extension method will create a default configuration which will look first into appsettings.json files then will look for Environment variables and at the end, it will use command line arguments.

      This part will also set up default logger sources (debug and console) and load the settings for logging from appsettings.json.

      After the CreateDefaultBuilder finishes, then Startup class is executed. First, the constructor code is executed. After that, services are added to DI container via AddServices method that lives in Startup class. After that, an order of middleware that will handle every incoming request is set up.

    20. Question 20. Talk About New .csproj File?

      Answer :

      .csproj file is now used as a place where we manage the NuGet packages for your application.

      File explorer and project explorer are now in sync. For .NET Core projects, you can easily drop a file from file explorer into a project or delete it from the file system and it will be gone from the project. No more source files in a .csproj file.

      You can now edit the .csproj file directly without unloading the project.

    21. Question 21. What Is Razor Pages?

      Answer :

      Razor Pages is a new feature of ASP.NET Core that makes coding page-focused scenarios easier and more productive.

      With Razor Pages, you have this one Razor file (.cshtml), and the code for a single page lives inside of that file, and that file also represents the URL structure of the app (more about this later). Therefore, you got everything inside of one file, and it just works.

      However, you CAN separate your code to the code behind file with .cshtml.cs extension. You would usually have your view model and handlers (like action methods in MVC) in that file and handle the logic there. Of course, you could also have your view model moved to separate place.

      Since Razor Pages is part of the MVC stack, you can use anything that comes with MVC inside of our Razor Pages.

    22. Question 22. What About Static Files In Asp.net Core (mvc)?

      Answer :

      All static files are now (by default) located inside of wwwroot folder. You store your CSS, JS, images, fonts  and others static content inside of it.

    23. Question 23. What Is Startup.cs In Asp.net Core?

      Answer :

      • In ASP.NET, Global.asax acts as the entry point for your application. 
      • In ASP.net Core,startup.cs is the entry point for your application.
      • In Startup.cs file
      • The constructor loads the AppSettings.json file using ConfigurationBuilder class
      • The ConfigureServices() method adds the services required by the application. For example, here you add MVC and Entity Framework to the services collection.
      • The Configure() method specifies and configures the services added earlier for application’s use.

    24. Question 24. What Are The Various Json Files In Asp.net Core?

      Answer :

      • global.json: can define solution level settings in global.json file 
      • launchsettings.json: can define project specific settings associated with each profile Visual Studio is configured to launch the application, including any environment variables that should be used. You can define framework for your project for compliation and debugging for specific profiles. 
      • appsettings.json: to store custom application setting, DB connection strings,Logging etc 
      • bundleconfig.json: can define the configuration for bundling and minification for the project. 
      • project.json: storing all project level configuration settings 
      • bower.json: Bower is a package manager for the web. Bower manages components that contain HTML, CSS, JavaScript, fonts or even image files. Bower installs the right versions of the packages you need and their dependencies

    25. Question 25. Differences Between .net Core And .net Framework?

      Answer :

      The differences between the two can be summarized in these three points:

      NuGet-based: .NET Core is distributed as a set of NuGet packages that allow app-local deployments. In contrast, the .NET Framework is always installed in a system-wide location. This difference doesn’t matter so much for class libraries; but it matters for applications as those are expected to deploy the closure of their dependencies. But we expect this model to change how quickly class library authors can take advantage of new functionality. Since the applications can simply deploy a new version (as opposed to having to wait until a given .NET Framework version is widely adopted), there is less of a penalty for component authors to take advantage of the latest features.

      Well layered: .NET Core was specifically designed to be layered. The goal was to create a .NET stack that can accommodate a wide variety of capabilities and system constraints without forcing customers to recompile their binaries and/or produce new assets. This means that we had to remove certain APIs because they tied lower level components to higher level components. In those cases, we provide alternatives, often in the form of extension methods.

      Free of problematic tech: .NET Core doesn’t include certain technologies we decided to discontinue because we found them to be problematic, for instance AppDomain and sandboxing. If the scenario still makes sense for .NET Core, our plan is to have replacements. For example, AssemblyLoadContext replaces AppDomains for loading and isolating assemblies.

    26. Question 26. Explain .net Family Of Frameworks?

      Answer :

      .NET Framework is the "full" or "traditional" flavor of .NET that's distributed with Windows. Use this when you are building a desktop Windows app or working with ASP.NET 4.5/4.6.

      .NET Core is cross-platform .NET that can run on Windows, Mac, and Linux. Use this when you want to build applications that can run on any platform, including ASP.NET Core (cross-platform web applications).

      Xamarin (Mono) is used for building mobile apps that can run on iOS, Android, or Windows Phone devices.

    27. Question 27. What Is The Relationship Between .net Core And .net Framework?

      Answer :

      .NET Core and the .NET Framework have (for the most part) a subset-superset relationship. .NET Core is named "Core" since it contains the core features from the .NET Framework, for both the runtime and framework libraries. For example, .NET Core and the .NET Framework share the GC, the JIT and types such as String and List

    28. Question 28. What Are Technologies Discontinued In .net Core?

      Answer :

      • Reflection
      • Appdomain
      • Remoting
      • Binary serialization
      • Sandboxing

;