ASP.NET MVC MCQ Banner

ASP.NET MVC Multiple Choice Questions (MCQs) and Answers

Master ASP.NET MVC with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of ASP.NET MVC concepts. Begin your placement preparation journey now!

Q121

Q121 What is the purpose of the [Authorize] attribute in ASP.NET MVC?

A

Restrict access to routes

B

Enable authentication

C

Handle model validation

D

Secure Razor views

Q122

Q122 What is Cross-Site Request Forgery (CSRF)?

A

A database attack

B

A form of XSS attack

C

An attack where unauthorized commands are performed on behalf of a user

D

A form validation error

Q123

Q123 How do Anti-Forgery tokens protect against CSRF attacks in ASP.NET MVC?

A

They encrypt sensitive data

B

They validate user identity

C

They ensure that a form request is from the authenticated user

D

They block unauthorized access

Q124

Q124 What is the purpose of HTTPS in ASP.NET MVC applications?

A

To optimize routing

B

To secure data in transit

C

To restrict controller access

D

To simplify model binding

Q125

Q125 How do you enable Anti-Forgery tokens in a Razor view?

A

@Html.EnableAntiForgeryToken()

B

@Html.AntiForgeryToken()

C

@Html.AddCSRF()

D

@Html.EnableCSRF()

Q126

Q126 How do you implement custom role-based authorization in ASP.NET MVC?

A

Create a custom AuthorizeAttribute

B

Add roles in Web.config

C

Use HttpContext.SetRole()

D

Modify RouteConfig

Q127

Q127 How do you enforce HTTPS for a controller in ASP.NET MVC?

A

Use the [HttpsRequired] attribute

B

Use the [RequireHttps] attribute

C

Define HTTPS in RouteConfig

D

Set HTTPS in Web.config

Q128

Q128 A [RequireHttps] attribute throws an error on localhost. What is the issue?

A

HTTPS is not enabled

B

Route is missing

C

Anti-Forgery token is missing

D

Certificate is invalid

Q129

Q129 An Anti-Forgery token validation fails. What could be the issue?

A

Token mismatch

B

Route conflict

C

Controller is missing

D

Invalid Razor syntax

Q130

Q130 What is bundling in ASP.NET MVC?

A

Combining multiple scripts or stylesheets into a single bundle

B

Caching views

C

Minimizing routing

D

Combining models

Q131

Q131 How does caching improve performance in ASP.NET MVC?

A

By storing frequently used data

B

By validating model bindings

C

By optimizing Razor syntax

D

By managing routes dynamically

Q132

Q132 What is output caching in ASP.NET MVC?

A

Storing HTML responses for reuse

B

Caching database queries

C

Caching controller actions

D

Storing Razor syntax

Q133

Q133 How do you enable output caching for an action in ASP.NET MVC?

A

Use the [Cache] attribute

B

Use the [OutputCache] attribute

C

Define caching in Web.config

D

Set caching in RouteConfig

Q134

Q134 How do you implement bundling in ASP.NET MVC?

A

Add bundles in the BundleConfig.cs file

B

Define bundles in RouteConfig

C

Use the @Html.Bundle() method

D

Add bundles in the controller

Q135

Q135 Bundling is not working in production. What could be the issue?

A

Minification is disabled

B

Debug mode is enabled

C

BundleConfig is missing

D

All of the above

Q136

Q136 Cached data is not being updated after changes. What could be the issue?

A

Cache duration is too long

B

Controller action is missing

C

OutputCache is invalid

D

BundleConfig is incorrect

Q137

Q137 What is the purpose of unit testing in ASP.NET MVC?

A

Test database performance

B

Test individual components

C

Test Razor syntax

D

Test server configurations

Q138

Q138 How does Dependency Injection improve testability in ASP.NET MVC?

A

By enabling the use of mocks

B

By reducing database calls

C

By optimizing routes

D

By simplifying view rendering

Q139

Q139 What is the role of a mocking framework in unit testing?

A

It handles routing

B

It creates fake dependencies

C

It validates Razor syntax

D

It simplifies model binding

Q140

Q140 How do you test a controller action using NUnit?

A

Create a mock HttpContext

B

Call the action directly and assert the result

C

Use RouteConfig to define the test

D

Create a Razor view for testing

Q141

Q141 How do you mock a DbContext for unit testing?

A

Use InMemoryDatabase

B

Use a mocking library

C

Manually create stubs

D

Both A and B

Q142

Q142 A unit test for a controller fails to execute. What could be the issue?

A

Dependency is not mocked

B

Route is undefined

C

ViewBag is missing

D

Razor syntax is incorrect

Q143

Q143 A mocked service in a unit test returns null. What is the issue?

A

Mock setup is incorrect

B

Service is not registered

C

Route is not defined

D

Controller is invalid

Q144

Q144 What is a common challenge in building large-scale ASP.NET MVC applications?

A

Handling complex routing

B

Managing multiple controllers

C

Ensuring loose coupling

D

Optimizing Razor syntax

Q145

Q145 How can you improve scalability in an ASP.NET MVC application?

A

Implement caching

B

Use asynchronous programming

C

Implement Dependency Injection

D

All of the above

Q146

Q146 What is a critical factor for maintaining performance in an enterprise MVC app?

A

Using Anti-Forgery tokens

B

Efficient database interactions

C

Creating complex Razor views

D

Minimizing controller actions

Q147

Q147 How do you handle dynamic routing in an ASP.NET MVC application?

A

Define routes in RouteConfig

B

Implement IRouteHandler

C

Use the [Route] attribute

D

Create custom routes in Global.asax

Q148

Q148 How do you structure an ASP.NET MVC project for a modular application?

A

Use areas for grouping related features

B

Add all controllers in a single folder

C

Define routes in views

D

Separate controllers and views in different projects

Q149

Q149 A large ASP.NET MVC app has slow response times. What could be the issue?

A

Too many database calls

B

Excessive view rendering

C

Incorrect route definitions

D

All of the above

Q150

Q150 How do you resolve memory leaks in an ASP.NET MVC application?

A

Use Dependency Injection

B

Dispose of unmanaged resources

C

Optimize Razor syntax

D

Enable caching

ad verticalad vertical
ad