ASP.NET Core MVC Interview

Authentication, Authorization, Security & State Management

ASP.NET Core MVC interview questions covering authentication, authorization, security & state management.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
101
Mid-LevelIntermediate

What is authentication in an ASP.NET Core MVC application?

Authentication determines who the current user is. ASP.NET Core authentication handlers examine credentials such as an authentication cookie or bearer token and, when valid, establish a ClaimsPrincipal on HttpContext.User.

102
Mid-LevelIntermediate

What is authorization in ASP.NET Core MVC?

Authorization determines whether an authenticated or anonymous user is allowed to access a resource or perform an operation. ASP.NET Core supports authorization through attributes, roles, claims, policies, requirements, and handlers.

103
Mid-LevelIntermediate

What is the difference between authentication and authorization?

Authentication answers 'Who is the user?' while authorization answers 'What is this user allowed to do?'. Authentication normally happens first so authorization can evaluate the resulting identity and claims.

104
Mid-LevelIntermediate

What does the [Authorize] attribute do?

Authorize requires the current request to satisfy the configured authorization rules. With no additional parameters, it normally requires an authenticated user.

105
Mid-LevelIntermediate

What does the [AllowAnonymous] attribute do?

AllowAnonymous marks an endpoint as not requiring authorization even when authorization is applied more broadly, such as at controller level.

106
Mid-LevelIntermediate

How does cookie authentication work in an MVC application?

Cookie authentication stores an encrypted authentication ticket in a browser cookie after sign-in. On later requests, the cookie authentication handler validates the cookie and reconstructs the user's ClaimsPrincipal.

107
Mid-LevelIntermediate

How do you sign a user in with cookie authentication?

After validating the user's credentials, create a ClaimsIdentity and ClaimsPrincipal and call SignInAsync with the configured authentication scheme. The authentication handler creates the protected cookie.

108
Mid-LevelIntermediate

How do you sign a user out of an MVC application?

Signing out removes or invalidates the authentication session for the specified scheme. With cookie authentication, SignOutAsync causes the authentication cookie to be removed from the response.

109
Mid-LevelIntermediate

What are claims in ASP.NET Core?

A claim is a name-value statement about a user, such as a user identifier, email address, department, permission, or role. Claims are stored in one or more ClaimsIdentity objects within the current ClaimsPrincipal.

110
Mid-LevelIntermediate

What is role-based authorization?

Role-based authorization allows access according to role membership, such as Admin, Editor, or Manager. The Authorize attribute can require one or more roles.

111
Mid-LevelIntermediate

What is policy-based authorization?

Policy-based authorization defines named authorization rules during application configuration. A policy can require authentication, claims, roles, custom requirements, or combinations of these rules.

112
Mid-LevelIntermediate

What are authorization requirements and handlers?

An authorization requirement represents a condition that must be satisfied, while an authorization handler contains logic that evaluates the requirement against the current user and optional resource.

113
Mid-LevelIntermediate

What is resource-based authorization?

Resource-based authorization evaluates permission against a particular resource instance rather than only endpoint metadata. For example, a user may edit an article only if the user owns that article or has an elevated permission.

114
Mid-LevelIntermediate

What is the difference between Challenge, Forbid, and Unauthorized?

Challenge asks the configured authentication system to handle an unauthenticated request, which may redirect a cookie-authenticated browser to a login page. Forbid indicates that the user is authenticated but is not permitted to access the resource.

115
Mid-LevelIntermediate

Why is HTTPS important for ASP.NET Core MVC security?

HTTPS encrypts HTTP traffic between the browser and server, protecting credentials, authentication cookies, anti-forgery tokens, form data, and page content from network interception and modification.

116
Mid-LevelIntermediate

What is Cross-Site Request Forgery (CSRF)?

CSRF occurs when a malicious site causes a user's browser to submit an unwanted state-changing request to another site where the user is already authenticated. Cookie authentication is particularly relevant because browsers can automatically attach authentication cookies.

117
Mid-LevelIntermediate

How does anti-forgery token validation work in MVC?

The application issues anti-forgery information to the client and expects the matching token information to be returned with a protected request. MVC validates the token before allowing the action to continue.

118
Mid-LevelIntermediate

What is Cross-Site Scripting (XSS), and how does Razor help prevent it?

XSS occurs when untrusted content is rendered as executable HTML or JavaScript in another user's browser. Razor HTML-encodes ordinary string output by default, which significantly reduces the risk when displaying untrusted text.

119
Mid-LevelIntermediate

What is an open redirect vulnerability in MVC?

An open redirect occurs when an application redirects to a user-controlled URL without verifying that the destination is safe. Attackers can use a trusted site's login or navigation flow to send users to a malicious external site.

120
Mid-LevelIntermediate

How should sensitive data be handled in MVC forms?

Do not trust hidden fields, disabled-looking controls, query strings, or other client-submitted values as authoritative security data. Values such as owner IDs, prices, roles, or approval status should be obtained or verified on the server when they affect security or business integrity.

121
Mid-LevelIntermediate

What is session state in ASP.NET Core MVC?

Session state stores per-user data across multiple HTTP requests using a session identifier, normally held in a cookie. The actual session data is stored by a configured server-side session provider.

122
Mid-LevelIntermediate

What is the difference between Session, TempData, ViewData, and ViewBag?

Session persists data across multiple requests for a user until it expires or is removed. TempData is designed for short-lived data that survives a redirect and is typically consumed after it is read.

123
Mid-LevelIntermediate

What are cookies, and how are they used in MVC applications?

Cookies are small values stored by the browser and sent to the server according to their domain, path, expiration, SameSite, Secure, and other settings. They can support authentication, preferences, correlation, anti-forgery mechanisms, and other browser state.

124
Mid-LevelIntermediate

What is the Data Protection system in ASP.NET Core?

ASP.NET Core Data Protection provides cryptographic APIs used by framework features and applications to protect data with encryption and integrity checks. Authentication cookies, TempData providers, and anti-forgery infrastructure rely on data-protection capabilities.

125
Mid-LevelIntermediate

What are best practices for authentication, authorization, security, and state management in MVC?

Use a proven authentication system such as ASP.NET Core Identity or correctly configured authentication handlers rather than building password and session security from scratch. Enforce authorization on controllers/actions or through policies, and use resource-based authorization when access depends on the specific record.