What is the primary purpose of ASP.NET Core?
a. To build cross-platform web applications and APIs
b. To create Windows Forms applications
c. To develop desktop applications
d. To manage databases
Answer: a. To build cross-platform web applications and APIs
What is the main component of the ASP.NET Core architecture responsible for handling HTTP requests?
a. Middleware
b. Controllers
c. Views
d. Models
Answer: a. Middleware
What is the role of the Startup class in an ASP.NET Core application?
a. To configure services and the application’s request pipeline
b. To manage database connections
c. To handle user authentication
d. To define data models
Answer: a. To configure services and the application’s request pipeline
What method is used to configure the request pipeline in the Startup class?
a. Configure()
b. Initialize()
c. Setup()
d. Build()
Answer: a. Configure()
How do you register services in ASP.NET Core?
a. By using the ConfigureServices() method in the Startup class
b. By configuring services in web.config
c. By adding services in the Controller constructor
d. By defining services in the application settings
Answer: a. By using the ConfigureServices() method in the Startup class
What is the purpose of the ConfigureServices() method in the Startup class?
a. To register application services and configure dependency injection
b. To set up middleware components
c. To handle request routing
d. To define view rendering logic
Answer: a. To register application services and configure dependency injection
What does the UseRouting() method do in the request pipeline?
a. It sets up the routing middleware to handle HTTP request routing
b. It configures authentication middleware
c. It initializes the database connection
d. It manages the application’s logging
Answer: a. It sets up the routing middleware to handle HTTP request routing
What is the purpose of the UseEndpoints() method?
a. To configure endpoint routing and map requests to endpoints
b. To set up middleware for handling exceptions
c. To manage user authentication
d. To configure logging services
Answer: a. To configure endpoint routing and map requests to endpoints
How do you add custom middleware to the request pipeline in ASP.NET Core?
a. By calling app.UseMiddleware<T>() in the Configure() method
b. By defining middleware in the ConfigureServices() method
c. By adding middleware in web.config
d. By using the Startup constructor
Answer: a. By calling app.UseMiddleware<T>() in the Configure() method
What is the purpose of dependency injection in ASP.NET Core?
a. To provide services to components and manage their lifetimes
b. To handle HTTP request routing
c. To manage view rendering
d. To configure static file serving
Answer: a. To provide services to components and manage their lifetimes
What is the default lifetime of a service registered with the Singleton service lifetime?
a. The service is created once and shared throughout the application’s lifetime
b. The service is created once per request
c. The service is created once per scope
d. The service is created every time it is requested
Answer: a. The service is created once and shared throughout the application’s lifetime
What is the difference between AddScoped() and AddTransient() service lifetimes?
a. AddScoped() creates a service instance per request, while AddTransient() creates a new instance every time it is requested
b. AddScoped() creates a singleton instance, while AddTransient() creates an instance per request
c. AddScoped() creates a new instance every time it is requested, while AddTransient() creates a singleton instance
d. AddScoped() and AddTransient() are identical in behavior
Answer: a. AddScoped() creates a service instance per request, while AddTransient() creates a new instance every time it is requested
What is the role of the IConfiguration interface in ASP.NET Core?
a. To provide access to configuration settings from various sources
b. To manage database connections
c. To handle HTTP requests
d. To configure middleware
Answer: a. To provide access to configuration settings from various sources
How do you configure settings in an ASP.NET Core application?
a. By using the IConfiguration interface and configuration providers
b. By defining settings in web.config
c. By setting up configuration in the Startup class
d. By using environment variables
Answer: a. By using the IConfiguration interface and configuration providers
What is the purpose of the IHostingEnvironment interface in ASP.NET Core?
a. To provide information about the hosting environment, such as development or production
b. To configure request routing
c. To manage service lifetimes
d. To handle user authentication
Answer: a. To provide information about the hosting environment, such as development or production
What method is used to create a new instance of the ASP.NET Core web host?
a. CreateDefaultBuilder()
b. BuildWebHost()
c. ConfigureWebHost()
d. CreateHostBuilder()
Answer: a. CreateDefaultBuilder()
How does ASP.NET Core support cross-platform development?
a. By being built on .NET Core, which is cross-platform
b. By using Windows-specific APIs
c. By requiring a Windows server for deployment
d. By only supporting IIS as a web server
Answer: a. By being built on .NET Core, which is cross-platform
What is the role of the IWebHost interface?
a. To manage the application’s web hosting environment
b. To configure middleware components
c. To define data models
d. To handle request routing
Answer: a. To manage the application’s web hosting environment
What is the purpose of the UseStaticFiles() method in ASP.NET Core?
a. To enable the serving of static files from the wwwroot directory
b. To configure middleware for handling requests
c. To manage application settings
d. To define routes for dynamic content
Answer: a. To enable the serving of static files from the wwwroot directory
How do you enable HTTPS redirection in an ASP.NET Core application?
a. By using the UseHttpsRedirection() method in the request pipeline
b. By configuring HTTPS in the web.config file
c. By setting up HTTPS in the controller
d. By adding HTTPS settings in the Startup constructor
Answer: a. By using the UseHttpsRedirection() method in the request pipeline
What is the role of the UseAuthentication() method?
a. To enable authentication middleware in the request pipeline
b. To configure authorization policies
c. To manage user sessions
d. To handle exception handling
Answer: a. To enable authentication middleware in the request pipeline
How do you handle authorization in an ASP.NET Core application?
a. By using the UseAuthorization() method to configure authorization middleware
b. By configuring authorization in web.config
c. By defining authorization rules in the controller
d. By using the [Authorize] attribute on controllers and actions
Answer: a. By using the UseAuthorization() method to configure authorization middleware
What is the role of the IApplicationBuilder interface?
a. To configure the request pipeline by defining middleware components
b. To manage application settings
c. To handle data access
d. To define routes for HTTP requests
Answer: a. To configure the request pipeline by defining middleware components
What is the purpose of the IStartup interface?
a. To define the configuration and request pipeline setup for an application
b. To manage data access
c. To configure authentication and authorization
d. To handle exception handling
Answer: a. To define the configuration and request pipeline setup for an application
How do you use environment-specific configuration in ASP.NET Core?
a. By using appsettings.{Environment}.json files
b. By defining configuration settings in web.config
c. By setting environment variables directly
d. By configuring settings in the Startup class
Answer: a. By using appsettings.{Environment}.json files
What is the role of the IWebHostBuilder interface?
a. To configure and build the web host for the application
b. To handle HTTP requests
c. To manage data access
d. To configure middleware components
Answer: a. To configure and build the web host for the application
How do you define a middleware component in ASP.NET Core?
a. By creating a class that includes an Invoke or InvokeAsync method
b. By configuring middleware in the Startup class
c. By defining middleware in web.config
d. By using the [Middleware] attribute
Answer: a. By creating a class that includes an Invoke or InvokeAsync method
What is the purpose of the UseMvc() method?
a. To configure MVC middleware for routing and handling requests
b. To manage static file serving
c. To set up authentication middleware
d. To handle exception handling
Answer: a. To configure MVC middleware for routing and handling requests
How do you enable routing in an ASP.NET Core application?
a. By using the UseRouting() method in the request pipeline
b. By configuring routing in web.config
c. By setting up routing in the Startup constructor
d. By defining routes in the controller
Answer: a. By using the UseRouting() method in the request pipeline
What is the role of the UseEndpoints() method in the request pipeline?
a. To map requests to endpoints defined in the application
b. To set up authentication and authorization middleware
c. To configure static file serving
d. To handle exception handling
Answer: a. To map requests to endpoints defined in the application
How do you register a custom service in ASP.NET Core?
a. By using the AddScoped(), AddTransient(), or AddSingleton() methods in ConfigureServices()
b. By defining services in the Startup class constructor
c. By adding services in web.config
d. By configuring services in the application settings
Answer: a. By using the AddScoped(), AddTransient(), or AddSingleton() methods in ConfigureServices()
What is the role of the IHostBuilder interface?
a. To configure and build the host for the application
b. To manage HTTP requests
c. To handle data access
d. To define routes for HTTP requests
Answer: a. To configure and build the host for the application
What is the purpose of the Configure() method in the Startup class?
a. To set up the request processing pipeline by configuring middleware
b. To register services with the dependency injection container
c. To manage data access
d. To handle application settings
Answer: a. To set up the request processing pipeline by configuring middleware
How do you handle exceptions in ASP.NET Core?
a. By using exception handling middleware, such as UseExceptionHandler()
b. By configuring exceptions in web.config
c. By defining exception handling in the controller
d. By setting up global error handling in the Startup constructor
Answer: a. By using exception handling middleware, such as UseExceptionHandler()
What is the role of the UseDeveloperExceptionPage() method?
a. To display detailed error information during development
b. To configure custom error handling pages
c. To manage data access errors
d. To handle authentication errors
Answer: a. To display detailed error information during development
How do you enable request logging in ASP.NET Core?
a. By configuring logging services in the ConfigureServices() method and using middleware for logging
b. By setting up logging in web.config
c. By defining logging settings in the Startup constructor
d. By using the [Log] attribute on controllers
Answer: a. By configuring logging services in the ConfigureServices() method and using middleware for logging
What is the role of the ILogger interface?
a. To provide logging functionality and manage log entries
b. To handle HTTP request routing
c. To manage application settings
d. To configure middleware components
Answer: a. To provide logging functionality and manage log entries
What does the UseRouting() method configure?
a. It sets up the routing middleware to handle HTTP request routing
b. It enables static file serving
c. It sets up authentication middleware
d. It manages exception handling
Answer: a. It sets up the routing middleware to handle HTTP request routing
How do you configure middleware components in ASP.NET Core?
a. By using the app.UseXXX() methods in the Configure() method of the Startup class
b. By defining middleware in web.config
c. By setting up middleware in the ConfigureServices() method
d. By using attributes on controller actions
Answer: a. By using the app.UseXXX() methods in the Configure() method of the Startup class
What is the purpose of the UseAuthorization() method in the request pipeline?
a. To enable authorization middleware for handling user permissions
b. To configure static file serving
c. To set up routing for requests
d. To manage exception handling
Answer: a. To enable authorization middleware for handling user permissions
How do you manage environment-specific settings in ASP.NET Core?
a. By using different configuration files for each environment (e.g., appsettings.Development.json)
b. By defining environment settings in web.config
c. By setting environment variables directly in the code
d. By configuring settings in the Startup class constructor
Answer: a. By using different configuration files for each environment (e.g., appsettings.Development.json)
What is the role of the IServiceCollection interface?
a. To register services with the dependency injection container
b. To handle HTTP requests
c. To manage application settings
d. To define routes for requests
Answer: a. To register services with the dependency injection container
How do you implement custom middleware in ASP.NET Core?
a. By creating a class with an Invoke or InvokeAsync method and using app.UseMiddleware<T>()
b. By defining middleware in web.config
c. By configuring middleware in the ConfigureServices() method
d. By using attributes on controllers
Answer: a. By creating a class with an Invoke or InvokeAsync method and using app.UseMiddleware<T>()
What is the purpose of the appsettings.json file in ASP.NET Core?
a. To store configuration settings for the application
b. To manage routing settings
c. To define middleware components
d. To handle user authentication
Answer: a. To store configuration settings for the application
What does the UseEndpoints() method configure?
a. It sets up endpoint routing to map requests to controllers and actions
b. It enables static file serving
c. It manages exception handling
d. It configures logging services
Answer: a. It sets up endpoint routing to map requests to controllers and actions
How does ASP.NET Core handle dependency injection?
a. By using a built-in service container to manage service lifetimes and dependencies
b. By requiring services to be manually instantiated
c. By using attributes to inject dependencies
d. By defining services in web.config
Answer: a. By using a built-in service container to manage service lifetimes and dependencies
What is the role of the UseStaticFiles() method?
a. To enable serving static files from the wwwroot directory
b. To configure authentication middleware
c. To set up routing for requests
d. To handle application settings
Answer: a. To enable serving static files from the wwwroot directory
How do you configure custom error handling in ASP.NET Core?
a. By using the UseExceptionHandler() method in the request pipeline
b. By setting up custom error pages in web.config
c. By defining error handling logic in the Startup class constructor
d. By using the [HandleError] attribute
Answer: a. By using the UseExceptionHandler() method in the request pipeline