ASP.NET Core MCQs

Which platform does ASP.NET Core support? A) Windows only B) Windows and macOS only C) Windows, macOS, and Linux D) Linux only Answer: C) Windows, macOS, and Linux What is the default dependency injection (DI) container in ASP.NET Core? A) Autofac B) Ninject C) Unity D) Built-in DI container Answer: D) Built-in DI container Which of the following is a new feature introduced in ASP.NET Core? A) Web Forms B) Web API C) Middleware D) SignalR Answer: C) Middleware What is the purpose of Startup.cs in an ASP.NET Core application? A) To configure services and the request pipeline B) To manage controllers C) To handle database connections D) To define routing Answer: A) To configure services and the request pipeline Which method in Startup.cs is used to configure HTTP request pipeline? A) ConfigureServices() B) Configure() C) ConfigurePipeline() D) Init() Answer: B) Configure() What is middleware in ASP.NET Core? A) A class that handles database connections B) A component that processes requests and responses C) A service to manage routing D) A tool for creating views Answer: B) A component that processes requests and responses How is a service registered for dependency injection in ASP.NET Core? A) services.AddSingleton() B) services.AddMvc() C) services.AddScoped() D) All of the above Answer: D) All of the above What does the IActionResult interface represent in ASP.NET Core? A) A service for dependency injection B) A model for the view C) A type that defines the result of an action method D) A component to manage database Answer: C) A type that defines the result of an action method In ASP.NET Core, what is the default environment when none is specified? A) Development B) Production C) Staging D) Test Answer: B) Production Which command is used to create a new ASP.NET Core project? A) dotnet new mvc B) dotnet create mvc C) aspnet new mvc D) aspnet create mvc Answer: A) dotnet new mvc What is the role of the app.UseRouting() method in ASP.NET Core? A) To configure services B) To define routing in the request pipeline C) To manage database connections D) To configure middleware Answer: B) To define routing in the request pipeline How can you specify a development environment in ASP.NET Core? A) Using environment variables B) Using appsettings.json C) By hardcoding it in Startup.cs D) By setting it in launchSettings.json Answer: A) Using environment variables What does Kestrel refer to in ASP.NET Core? A) A built-in web server B) A database management system C) A middleware component D) A templating engine Answer: A) A built-in web server What is the primary difference between AddTransient and AddSingleton in ASP.NET Core DI? A) AddTransient creates a new instance per request, while AddSingleton creates one instance for the entire application B) AddTransient is for MVC controllers only, AddSingleton for services C) AddTransient is for small services, AddSingleton for large ones D) AddTransient works with HTTP only, AddSingleton with HTTPS Answer: A) AddTransient creates a new instance per request, while AddSingleton creates one instance for the entire application Which of the following is true about Razor Pages in ASP.NET Core? A) Razor Pages use only controllers B) Razor Pages are used for Web Forms C) Razor Pages focus on page-based scenarios D) Razor Pages cannot use dependency injection Answer: C) Razor Pages focus on page-based scenarios How do you add middleware components to the request pipeline in ASP.NET Core? A) Using app.UseMiddleware<T>() B) Using app.UseMvc() C) By adding them to the ConfigureServices method D) By editing the launchSettings.json Answer: A) Using app.UseMiddleware<T>() What is the purpose of app.UseEndpoints() in ASP.NET Core? A) To configure database access B) To define endpoint routing for HTTP requests C) To handle session state D) To configure environment settings Answer: B) To define endpoint routing for HTTP requests Which of the following databases is integrated easily with ASP.NET Core using Entity Framework Core? A) MySQL B) PostgreSQL C) SQL Server D) All of the above Answer: D) All of the above What is the default template engine used in ASP.NET Core MVC? A) Razor B) PHP C) JSP D) Vue.js Answer: A) Razor What is the role of IHostingEnvironment in ASP.NET Core? A) To configure database settings B) To provide information about the hosting environment C) To define middleware D) To manage routing Answer: B) To provide information about the hosting environment What is the purpose of the appsettings.json file in ASP.NET Core? A) To define middleware B) To store configuration settings C) To manage session state D) To configure routing Answer: B) To store configuration settings What does the term “cross-platform” mean in the context of ASP.NET Core? A) The ability to run on multiple operating systems B) The ability to handle multiple HTTP requests C) The ability to connect to multiple databases D) The ability to run multiple applications simultaneously Answer: A) The ability to run on multiple operating systems How can you enforce HTTPS in an ASP.NET Core application? A) Using app.UseHttpsRedirection() B) Using app.UseHttps() C) By modifying Startup.cs D) By setting environment variables Answer: A) Using app.UseHttpsRedirection() Which of the following is used to handle exceptions globally in ASP.NET Core? A) ExceptionFilter B) GlobalException C) UseExceptionHandler middleware D) ErrorHandlingController Answer: C) UseExceptionHandler middleware How can you enable static file serving in ASP.NET Core? A) app.UseStaticFiles() B) app.EnableStaticFiles() C) app.ServeStaticFiles() D) app.LoadStaticFiles() Answer: A) app.UseStaticFiles() What is the main purpose of the ConfigureServices method in Startup.cs? A) To configure the application request pipeline B) To register services with the DI container C) To manage routing D) To define middleware Answer: B) To register services with the DI container What is the purpose of IConfiguration in ASP.NET Core? A) To handle requests and responses B) To load configuration settings from various sources C) To manage session state D) To define routes Answer: B) To load configuration settings from various sources Which hosting model is used by default in ASP.NET Core? A) In-process B) Out-of-process C) Hybrid D) Dual-mode Answer: A) In-process What is the main advantage of using Entity Framework Core in ASP.NET Core? A) It provides ORM capabilities B) It handles middleware configuration C) It optimizes routing D) It manages DI containers Answer: A) It provides ORM capabilities Which file is used to configure logging in ASP.NET Core? A) appsettings.json B) launchSettings.json C) web.config D) logging.json Answer: A) appsettings.json Which package is required to enable Razor Pages in ASP.NET Core? A) Microsoft.AspNetCore.Mvc.RazorPages B) Microsoft.AspNetCore.Mvc.Views C) Microsoft.AspNetCore.Razor D) Microsoft.AspNetCore.Routing Answer: A) Microsoft.AspNetCore.Mvc.RazorPages How do you handle form submissions in ASP.NET Core MVC? A) Using POST requests in a controller B) Using GET requests in a controller C) Using PUT requests in a controller D) Using PATCH requests in a controller Answer: A) Using POST requests in a controller Which of the following is a built-in logging provider in ASP.NET Core? A) Console B) File C) SQL D) Email Answer: A) Console What is the purpose of UseAuthentication() in ASP.NET Core? A) To enforce authorization B) To enable user authentication C) To manage sessions D) To handle routing Answer: B) To enable user authentication Which feature is used for handling WebSocket connections in ASP.NET Core? A) SignalR B) gRPC C) MVC D) Razor Pages Answer: A) SignalR What is the primary use of Razor in ASP.NET Core? A) To render dynamic web content B) To manage routing C) To process HTTP requests D) To handle sessions Answer: A) To render dynamic web content Which of the following is a benefit of using ASP.NET Core over traditional ASP.NET? A) Better performance and modularity B) Larger community support C) No need for dependency injection D) Limited platform support Answer: A) Better performance and modularity How do you define routing in an ASP.NET Core MVC application? A) In Startup.cs using app.UseEndpoints() B) In appsettings.json C) By modifying Program.cs D) Using a special controller attribute Answer: A) In Startup.cs using app.UseEndpoints() What is the purpose of ViewComponent in ASP.NET Core MVC? A) To create reusable components for views B) To manage routing C) To handle database operations D) To serve static files Answer: A) To create reusable components for views Which of the following allows two-way binding between the UI and backend in ASP.NET Core? A) Blazor B) Razor Pages C) MVC D) Web API Answer: A) Blazor What does the services.AddMvc() method do in ASP.NET Core? A) Adds MVC services to the dependency injection container B) Configures session state management C) Adds middleware for static file handling D) Configures environment settings Answer: A) Adds MVC services to the dependency injection container How do you handle session data in ASP.NET Core? A) Using HttpContext.Session B) Using HttpRequest.Session C) Using ViewData D) Using TempData Answer: A) Using HttpContext.Session Which of the following is a valid data format for Web API responses in ASP.NET Core? A) JSON B) XML C) Both JSON and XML D) CSV Answer: C) Both JSON and XML What does UseCors() do in ASP.NET Core? A) Enables Cross-Origin Resource Sharing B) Enables caching C) Handles client requests D) Manages sessions Answer: A) Enables Cross-Origin Resource Sharing What is the primary purpose of Model Binding in ASP.NET Core? A) To map incoming request data to action method parameters B) To manage routing C) To render views D) To handle middleware Answer: A) To map incoming request data to action method parameters What is the role of Tag Helpers in ASP.NET Core? A) To create reusable HTML elements B) To handle routing C) To manage sessions D) To process HTTP requests Answer: A) To create reusable HTML elements
All Copyrights Reserved 2025 Reserved by T4Tutorials