ASP.NET Core Practice Exam: Questions and Answers, Exams of Technology

A practice exam for asp.net core, featuring multiple-choice questions and detailed explanations. It covers essential topics such as middleware, configuration, dependency injection, mvc pattern, entity framework core, and security. This resource is designed to help developers test their knowledge and prepare for asp.net core certifications or job interviews. The questions address key concepts like kestrel, iconfiguration, razor pages, and jwt bearer authentication, offering a comprehensive review of asp.net core fundamentals and best practices. It also includes questions on content negotiation, api documentation using swagger, and deployment strategies, making it a valuable tool for both beginners and experienced developers.

Typology: Exams

2025/2026

Available from 12/30/2025

shilpi-jain-1
shilpi-jain-1 šŸ‡®šŸ‡³

4.2

(5)

29K documents

1 / 80

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASP NET Practice Exam
Question 1. Which technology is cross-platform, open-source, and intended for modern web
development?
A) .NET Framework
B) .NET Core
C) ASP.NET Web Forms
D) Classic ASP
Answer: B
Explanation: .NET Core is open-source and cross-platform, designed for modern development, whereas
.NET Framework is Windows-only.
Question 2. What does the wwwroot folder in an ASP.NET Core project contain?
A) Middleware components
B) Static files like CSS, JS, and images
C) Application settings
D) Controller classes
Answer: B
Explanation: The wwwroot folder is the web root for static files served directly to clients.
Question 3. Which file typically contains the entry point for an ASP.NET Core application?
A) Startup.cs
B) Program.cs
C) appsettings.json
D) launchSettings.json
Answer: B
Explanation: Program.cs contains the Main method, the entry point for the application.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50

Partial preview of the text

Download ASP.NET Core Practice Exam: Questions and Answers and more Exams Technology in PDF only on Docsity!

Question 1. Which technology is cross-platform, open-source, and intended for modern web development? A) .NET Framework B) .NET Core C) ASP.NET Web Forms D) Classic ASP Answer: B Explanation: .NET Core is open-source and cross-platform, designed for modern development, whereas .NET Framework is Windows-only. Question 2. What does the wwwroot folder in an ASP.NET Core project contain? A) Middleware components B) Static files like CSS, JS, and images C) Application settings D) Controller classes Answer: B Explanation: The wwwroot folder is the web root for static files served directly to clients. Question 3. Which file typically contains the entry point for an ASP.NET Core application? A) Startup.cs B) Program.cs C) appsettings.json D) launchSettings.json Answer: B Explanation: Program.cs contains the Main method, the entry point for the application.

Question 4. What is the main benefit of ASP.NET Core's modular middleware pipeline? A) It eliminates the need for controllers B) Middleware can be added, removed, and ordered as needed C) It replaces the need for a web server D) It forces a fixed processing order Answer: B Explanation: The middleware pipeline is highly configurable, allowing developers to control request processing. Question 5. Which hosting model uses Kestrel as the web server with IIS acting only as a reverse proxy? A) In-process hosting B) Out-of-process hosting C) Integrated hosting D) Static hosting Answer: B Explanation: Out-of-process hosting uses Kestrel for requests, with IIS as a reverse proxy. Question 6. What is the primary purpose of the IConfiguration interface in ASP.NET Core? A) Rendering HTML B) Accessing configuration values C) Handling authentication D) Managing database migrations Answer: B Explanation: IConfiguration is used to access configuration data from multiple sources. Question 7. Which method is used to add custom middleware to the request pipeline?

B) AddTransient C) AddSingleton D) AddService Answer: C Explanation: AddSingleton registers a service for the application's lifetime. Question 11. In the MVC pattern, which component handles user requests and returns responses? A) Model B) View C) Controller D) Middleware Answer: C Explanation: Controllers handle incoming requests and generate responses. Question 12. How does attribute routing differ from conventional routing in ASP.NET Core MVC? A) Attribute routing uses attributes on actions or controllers B) Attribute routing is only for static files C) Attribute routing is slower D) Attribute routing is deprecated Answer: A Explanation: Attribute routing defines routes directly with attributes. Question 13. What is the primary use of ViewBag in ASP.NET Core MVC? A) Strongly-typed model binding B) Passing temporary data from controller to view

C) Handling authentication D) Managing middleware Answer: B Explanation: ViewBag is a dynamic object for passing data from controllers to views. Question 14. In Razor Pages, what method handles GET requests by default? A) OnPost B) OnGet C) HandleGet D) Execute Answer: B Explanation: OnGet is used in Razor Pages to handle HTTP GET requests. Question 15. What does the asp-for Tag Helper do in a Razor view? A) Generates a link to a controller B) Binds an HTML element to a model property C) Validates JavaScript code D) Adds anti-forgery tokens Answer: B Explanation: asp-for binds HTML elements to model properties, simplifying data binding. Question 16. Which pattern is used to map relational data to objects in EF Core? A) Factory pattern B) Singleton pattern C) Object-Relational Mapping (ORM)

Answer: B Explanation: TempData temporarily holds data during a redirect between requests. Question 20. Which caching strategy is best for sharing cache across multiple servers? A) In-memory caching B) Output caching C) Distributed caching D) Page-level caching Answer: C Explanation: Distributed caching (e.g., Redis) shares cached data among servers. Question 21. What is the role of the Developer Exception Page middleware? A) Handles authentication B) Shows detailed error information in development C) Logs requests to a file D) Caches responses Answer: B Explanation: This middleware provides detailed error information during development. Question 22. Which annotation enforces required input on a model property? A) [EmailAddress] B) [Range] C) [Required] D) [StringLength] Answer: C

Explanation: [Required] ensures the property must have a value. Question 23. What does the Anti-Forgery Token protect against? A) SQL Injection B) Cross-Site Request Forgery (CSRF) C) Cross-Site Scripting (XSS) D) Phishing Answer: B Explanation: Anti-forgery tokens prevent CSRF attacks. Question 24. What is ASP.NET Core Identity primarily used for? A) Rendering views B) Managing users, roles, and authentication C) Logging errors D) Handling caching Answer: B Explanation: Identity provides authentication, authorization, and user management. Question 25. Which authentication scheme is commonly used for APIs? A) Cookie authentication B) JWT Bearer authentication C) Windows authentication D) Forms authentication Answer: B Explanation: JWT Bearer tokens are widely used for securing APIs.

Question 29. Which HTTP verb is typically used for updating a resource via a Web API? A) GET B) POST C) PUT D) DELETE Answer: C Explanation: PUT is used for updating resources in RESTful APIs. Question 30. What class should an API controller inherit from? A) Controller B) ControllerBase C) PageModel D) DbContext Answer: B Explanation: ControllerBase provides features needed for APIs without view rendering. Question 31. What is content negotiation in ASP.NET Core Web API? A) Serving static files B) Determining the response format (e.g., JSON, XML) C) Handling authentication D) Managing database migrations Answer: B Explanation: Content negotiation selects the correct response format for clients. Question 32. Which tool is commonly used for API documentation and testing in ASP.NET Core?

A) Entity Framework B) Swashbuckle (Swagger) C) SignalR D) Kestrel Answer: B Explanation: Swashbuckle generates Swagger-based API documentation and UI. Question 33. What is the function of the dotnet publish command? A) Starts a development server B) Compiles and prepares an application for deployment C) Runs unit tests D) Seeds the database Answer: B Explanation: dotnet publish compiles the app and copies files for deployment. Question 34. How do you log messages in ASP.NET Core? A) System.Diagnostics.Trace B) ILogger interface C) Console.WriteLine only D) appsettings.json Answer: B Explanation: ILogger is the preferred way to log messages in ASP.NET Core. Question 35. What is the advantage of using async/await in controller actions? A) Reduces memory usage

C) Editing the database schema D) Writing custom JavaScript Answer: B Explanation: Including validation scripts and using Data Annotations enables client-side validation. Question 39. What does AddScoped service lifetime mean? A) One instance per application B) One instance per request C) Multiple instances per request D) One instance per thread Answer: B Explanation: Scoped services are created once per client request. Question 40. Which extension method is used to add routing middleware? A) UseRouting B) AddSingleton C) AddRouting D) MapControllers Answer: A Explanation: UseRouting adds routing middleware to the pipeline. Question 41. What does the Developer Exception Page middleware display? A) User-friendly error messages B) Detailed exception stack traces for developers C) Only HTTP status codes

D) Custom error pages Answer: B Explanation: It provides detailed exception information during development. Question 42. What is the main difference between AddTransient and AddSingleton lifetimes? A) AddTransient creates a new instance each time; AddSingleton creates one for the app's lifetime B) No difference C) AddTransient is for database connections D) AddSingleton is for authentication only Answer: A Explanation: Transient creates new instances; Singleton uses one instance for the entire application. Question 43. What is the use of the UseAuthorization middleware? A) Handles routing B) Enforces authorization policies C) Renders views D) Serves static files Answer: B Explanation: UseAuthorization enforces authorization after authentication. Question 44. What is the default folder for views in an MVC project? A) wwwroot B) Views C) Controllers D) Models

Explanation: Data seeding populates the database with initial data. Question 48. Which method in DbContext saves changes to the database? A) SaveEntities B) SaveChanges C) Commit D) Flush Answer: B Explanation: SaveChanges persists changes from the context to the database. Question 49. What is the main limitation of cookies for client-side state? A) They are always encrypted B) Limited size and security risks C) Unlimited storage D) Not accessible to JavaScript Answer: B Explanation: Cookies are small and can be vulnerable to attacks if not handled securely. Question 50. What does the session state allow you to do? A) Store per-user data on the server B) Cache static files C) Manage connection strings D) Store application-wide data only Answer: A Explanation: Session state stores data for individual users on the server.

Question 51. How does TempData differ from Session state? A) TempData lasts across redirects, Session lasts for the user session B) Both last for the same duration C) TempData is for static files only D) Session cannot store complex objects Answer: A Explanation: TempData persists across a redirect, while Session persists for the session duration. Question 52. Which attribute is used to specify the range of valid values for a property? A) [Required] B) [Range] C) [StringLength] D) [EmailAddress] Answer: B Explanation: [Range] restricts values to a specified range. Question 53. What is the purpose of the Cache Tag Helper in Razor views? A) Serve static files B) Cache dynamic content in views C) Store configuration D) Manage database connections Answer: B Explanation: The Cache Tag Helper caches rendered content to improve performance.

A) Validates model state B) Enforces CSRF protection on POST actions C) Encrypts cookies D) Handles authentication Answer: B Explanation: It ensures POST requests include a valid anti-forgery token. Question 58. How do you create a custom middleware in ASP.NET Core? A) Implement IMiddleware or use a RequestDelegate B) Add a new View C) Edit appsettings.json D) Inherit from Controller Answer: A Explanation: Custom middleware is created by implementing IMiddleware or using a RequestDelegate. Question 59. What does policy-based authorization allow? A) Only role checks B) Complex authorization rules beyond roles C) No custom logic D) Authentication only Answer: B Explanation: Policies allow defining complex rules for authorization checks. Question 60. Which method in Startup.cs is used to add middleware components? A) Configure

B) ConfigureServices C) Main D) Build Answer: A Explanation: The Configure method sets up middleware in the pipeline. Question 61. What is the @page directive used for in Razor Pages? A) Enabling MVC B) Designating a Razor file as a page endpoint C) Configuring middleware D) Registering services Answer: B Explanation: @page identifies a Razor file as a page that can handle requests. Question 62. What is the main purpose of the IActionResult return type? A) To specify middleware B) To allow multiple response types from an action C) For data annotation D) To manage dependency injection Answer: B Explanation: IActionResult enables actions to return various result types. Question 63. What does the UseEndpoints middleware do? A) Adds routing B) Maps route endpoints to handlers