MCQs on C# for Web Development (ASP.NET Core) | C#

This set of 30 multiple-choice questions (MCQs) covers essential topics related to ASP.NET Core for web development. It includes questions on MVC Architecture, RESTful API Development, Entity Framework Core, Authentication, Authorization, and Middleware. Perfect for anyone looking to master web development using C# and ASP.NET Core.


1. Introduction to ASP.NET Core

  1. Which of the following is the primary purpose of ASP.NET Core?
    • A) Build desktop applications
    • B) Build web applications and APIs
    • C) Build mobile applications
    • D) Build games
  2. What is the latest version of ASP.NET Core as of 2024?
    • A) ASP.NET Core 6
    • B) ASP.NET Core 7
    • C) ASP.NET Core 8
    • D) ASP.NET Core 5
  3. Which of the following is NOT a feature of ASP.NET Core?
    • A) Cross-platform support
    • B) In-built dependency injection
    • C) Built-in support for Web Forms
    • D) Lightweight and high-performance
  4. How is an ASP.NET Core application typically hosted?
    • A) In a Windows environment only
    • B) In a Linux or Windows environment
    • C) Only in cloud-based platforms
    • D) On an IIS server exclusively
  5. Which of the following tools is used to create an ASP.NET Core project?
    • A) Visual Studio
    • B) Notepad++
    • C) Eclipse
    • D) Xcode

2. MVC Architecture

  1. In ASP.NET Core MVC, what does the “C” in MVC stand for?
    • A) Configuration
    • B) Control
    • C) Content
    • D) Controller
  2. Which of the following is used to handle HTTP requests in the MVC pattern of ASP.NET Core?
    • A) Models
    • B) Views
    • C) Controllers
    • D) Middleware
  3. In MVC architecture, which component is responsible for defining the structure of data?
    • A) View
    • B) Model
    • C) Controller
    • D) API
  4. How does an ASP.NET Core MVC controller return a response to the client?
    • A) By returning a View
    • B) By returning a Model
    • C) By returning a DataTable
    • D) By returning an API endpoint
  5. Which of the following attributes is used to define a controller in ASP.NET Core MVC?
    • A) [ApiController]
    • B) [Controller]
    • C) [HttpController]
    • D) [MvcController]

3. RESTful API Development

  1. Which HTTP verb is used to retrieve data from a RESTful API?
    • A) POST
    • B) PUT
    • C) GET
    • D) DELETE
  2. What is the main purpose of a RESTful API in web development?
    • A) To process forms
    • B) To provide a graphical interface
    • C) To allow communication between client and server
    • D) To perform complex computations
  3. Which attribute is used to define a route for a RESTful API controller in ASP.NET Core?
    • A) [Route]
    • B) [HttpGet]
    • C) [Controller]
    • D) [RoutePrefix]
  4. What is a commonly used data format for exchanging information in RESTful APIs?
    • A) HTML
    • B) XML
    • C) JSON
    • D) CSV
  5. Which of the following methods is used to handle HTTP POST requests in an ASP.NET Core controller?
    • A) Post()
    • B) Create()
    • C) HttpPost()
    • D) Add()

4. Entity Framework Core

  1. What is Entity Framework Core primarily used for in ASP.NET Core applications?
    • A) To handle routing
    • B) To perform database operations
    • C) To process authentication
    • D) To manage user input
  2. Which method in Entity Framework Core is used to save changes to the database?
    • A) SaveChangesAsync()
    • B) CommitChanges()
    • C) ApplyChanges()
    • D) PersistChanges()
  3. In Entity Framework Core, what is the purpose of DbContext?
    • A) To define the structure of the application
    • B) To handle database connections and queries
    • C) To manage authentication
    • D) To define routes in the application
  4. Which of the following is a valid data provider for Entity Framework Core?
    • A) SQL Server
    • B) MySQL
    • C) PostgreSQL
    • D) All of the above
  5. How are relationships between entities defined in Entity Framework Core?
    • A) Using foreign keys
    • B) Using relationships defined in the model
    • C) Using annotations or Fluent API
    • D) Both B and C

5. Authentication and Authorization

  1. What is the main purpose of authentication in ASP.NET Core?
    • A) To ensure the user has proper access rights
    • B) To manage user input
    • C) To encrypt data
    • D) To validate forms
  2. Which of the following middleware is used to authenticate a user in ASP.NET Core?
    • A) AuthenticationMiddleware
    • B) IdentityMiddleware
    • C) CookieAuthentication
    • D) AuthorizeMiddleware
  3. In ASP.NET Core, which attribute is used to restrict access to an action or controller for authorized users only?
    • A) [Authorize]
    • B) [Authentication]
    • C) [UserRequired]
    • D) [AccessControl]
  4. Which of the following is commonly used for handling user identity in ASP.NET Core applications?
    • A) Session
    • B) Cookie Authentication
    • C) API Keys
    • D) JWT Tokens
  5. What is the purpose of authorization in ASP.NET Core?
    • A) To authenticate the user
    • B) To assign permissions and roles to users
    • C) To validate user inputs
    • D) To encrypt data

6. Middleware in ASP.NET Core

  1. What is middleware in the context of ASP.NET Core?
    • A) A library for handling authentication
    • B) A set of components that handle HTTP requests and responses
    • C) A service that defines routes
    • D) A data management tool
  2. Which method is used to add middleware to the request pipeline in ASP.NET Core?
    • A) ConfigureServices()
    • B) ConfigureMiddleware()
    • C) UseMiddleware()
    • D) AddMiddleware()
  3. Which of the following is an example of built-in middleware in ASP.NET Core?
    • A) StaticFiles
    • B) MVC
    • C) Authentication
    • D) All of the above
  4. How is exception handling managed in ASP.NET Core middleware?
    • A) Using the UseExceptionHandler method
    • B) Using the CatchExceptions middleware
    • C) By writing custom exception handlers
    • D) Both A and C
  5. Which of the following is the correct order of middleware in the request pipeline for ASP.NET Core applications?
    • A) Authentication → Authorization → MVC
    • B) MVC → Authentication → Authorization
    • C) Authorization → Authentication → MVC
    • D) MVC → Authentication → StaticFiles

Answer Key

QnoAnswer (Option with Text)
1B) Build web applications and APIs
2C) ASP.NET Core 8
3C) Built-in support for Web Forms
4B) In a Linux or Windows environment
5A) Visual Studio
6D) Controller
7C) Controllers
8B) Model
9A) By returning a View
10B) [Controller]
11C) GET
12C) To allow communication between client and server
13A) [Route]
14C) JSON
15C) HttpPost()
16B) To perform database operations
17A) SaveChangesAsync()
18B) To handle database connections and queries
19D) All of the above
20D) Both B and C
21A) To ensure the user has proper access rights
22C) CookieAuthentication
23A) [Authorize]
24D) JWT Tokens
25B) To assign permissions and roles to users
26B) A set of components that handle HTTP requests and responses
27C) UseMiddleware()
28D) All of the above
29A) Using the UseExceptionHandler method
30A) Authentication → Authorization → MVC

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top