ASP. Net Questions Flashcards
What is the key difference between ASP.NET Web Forms and ASP.NET MVC?
Web Forms: Page-centric model, server controls, ViewState.
MVC: Separation of concerns, more control over HTML, Testability.
Explain the MVC design pattern.
Model: Data and business logic.
View: Presentation layer.
Controller: Handles user input and controls flow.
What is ViewData and ViewBag in MVC?
Mechanisms to pass data from controller to view.
What is a Razor View in ASP.NET MVC?
View engine for generating HTML markup in MVC.
How can you achieve URL routing in ASP.NET MVC?
Define routes in the RouteConfig file.
What are the key benefits of ASP.NET Core over traditional ASP.NET?
Cross-platform, lightweight, better performance, modularity.
Explain the concept of Middleware in ASP.NET Core.
Components that can handle requests and responses globally.
What is Dependency Injection in ASP.NET Core?
Pattern for injecting dependencies into classes instead of hard-coding them.
How does configuration management work in ASP.NET Core?
Configuration stored in appsettings.json, environment variables, etc.
What is the Program.cs and Startup.cs files used for in ASP.NET Core?
Program.cs: Main entry point.
Startup.cs: Configuration of services and middleware.
Explain RESTful architecture.
Representational State Transfer, using HTTP methods to interact with resources.
What are the HTTP methods used in RESTful APIs?
GET, POST, PUT, DELETE, PATCH, etc.
How do you handle versioning in a Web API?
URL versioning, media type versioning, query string versioning.
What is content negotiation in Web API?
Process of selecting the appropriate response format based on client request headers.
How can you handle errors in a Web API?
Use HTTP status codes, provide meaningful error messages, and use exception filters.
Explain the concept of URL routing.
Mapping URLs to controller actions in MVC
How can you define custom routes in ASP.NET MVC?
Use Route attribute or configure routes in RouteConfig.
What is attribute routing?
Defining routes directly on controller actions using attributes.
How does routing work in ASP.NET Core?
Similar to MVC, use UseEndpoints() in Startup.cs.
What is the purpose of cookies in web development?
Storing small pieces of data on the client side.
How do cookies differ from sessions?
Cookies are stored on the client, sessions are stored on the server.
Explain how sessions work in ASP.NET.
Server-side storage of user-specific data.
What is TempData in ASP.NET MVC?
Stores data between two consecutive requests.
How can you manage application state in ASP.NET Core?
Use services like MemoryCache or distributed caches like Redis.
What is authentication? What is authorization?
Authentication: Verifying user identity.
Authorization: Determining user’s access rights.
Explain the concept of Identity in ASP.NET Core.
Framework for managing user accounts and authentication.
What is OAuth and how is it used for authentication?
Open standard for authorization, allowing third-party applications to access resources on behalf of users.
What is JWT and how does it work?
JSON Web Token: Compact, URL-safe means of representing claims between two parties.
How do you secure a Web API using JWT?
Issue and validate JWT tokens, verify claims.
What is middleware in ASP.NET Core?
Software components that form the request/response pipeline.
How can you create custom middleware in ASP.NET Core?
Implement the IMiddleware interface or use the UseMiddleware extension method.
Explain the order of execution of middleware in ASP.NET Core.
Middlewares are executed in the order they are added to the pipeline.
How can you conditionally branch the pipeline based on a request’s properties?
Use Map and MapWhen methods.
What is the purpose of endpoint routing middleware in ASP.NET Core?
Matches requests to endpoints defined in the application.
What is ViewState in ASP.NET Web Forms?
ViewState is a client-side state management technique that allows preserving the state of server controls across postbacks
Explain the concept of Model Binding in ASP.NET MVC.
Model binding maps HTTP request data to action method parameters or model properties.
What is the role of the Global.asax file in ASP.NET applications?
Global.asax contains application-level events and configuration settings for the application lifecycle.
What is the purpose of TempDataDictionary in ASP.NET MVC?
TempDataDictionary is used to share data between actions during a single user’s session.
How does Routing in ASP.NET MVC contribute to SEO-friendly URLs?
Routing allows developers to create meaningful URLs that enhance search engine optimization.
Explain the concept of Areas in ASP.NET MVC.
Areas allow structuring an MVC application into smaller, manageable sections.
What is the role of the App_Start folder in ASP.NET MVC?
App_Start contains configuration code that runs on application startup.
How do you handle exceptions in ASP.NET MVC?
Using try-catch blocks, custom error pages, or global exception filters.
What is the purpose of the Razor View Engine’s @section directive?
It defines named content that can be rendered in a layout view.
What is an ActionResult in ASP.NET MVC?
An ActionResult is the return type of an action method, representing the result of the action’s execution.
What is the role of the Kestrel server in ASP.NET Core?
Kestrel is a cross-platform web server used to host ASP.NET Core applications.
How does Dependency Injection improve the testability of ASP.NET Core applications?
Dependency Injection allows for easier isolation and mocking of dependencies during testing.
What is the purpose of the appsettings.json file in ASP.NET Core?
It stores application configuration settings in a JSON format
What are Tag Helpers in ASP.NET Core?
Tag Helpers are HTML-like elements that enable server-side code execution in Razor views.
Explain the concept of Razor Pages in ASP.NET Core.
Razor Pages is a page-based programming model that simplifies building web UI.
What is the purpose of the IWebHostEnvironment interface in ASP.NET Core?
It provides information about the environment in which the application is running.
How does ASP.NET Core achieve cross-platform compatibility?
Through the use of .NET Core runtime, which is designed to be platform-agnostic
What is the role of the app.UseAuthentication() and app.UseAuthorization() middleware?
app.UseAuthentication() sets up authentication, and app.UseAuthorization() sets up authorization in the request pipeline.
How can you host multiple ASP.NET Core applications on the same server?
By configuring different ports, paths, or domains for each application.
Explain the purpose of the IApplicationBuilder interface in ASP.NET Core.
It is used to configure the request processing pipeline.
What is HATEOAS (Hypermedia as the Engine of Application State) in RESTful APIs?
It refers to including hypermedia links in responses to guide client navigation.
How can you enable CORS (Cross-Origin Resource Sharing) in a Web API?
By configuring CORS policies to allow cross-origin requests.
What is versioning in the context of a Web API?
Versioning ensures backward compatibility when making changes to the API.
Explain the concept of content negotiation in Web API.
It involves the server and client agreeing on a suitable response format based on request headers.
What is the purpose of the [FromBody] attribute in Web API parameter binding?
It binds complex types from the request body to the parameter.
How can you implement rate limiting in a Web API?
By tracking and limiting the number of requests from a single client within a specified time frame.
What is the role of the IHttpActionResult interface in Web API?
It provides better control over HTTP response creation in action methods.
Explain the concept of content negotiation in Web API.
It involves the server and client agreeing on a suitable response format based on request headers.
What is the purpose of the [FromBody] attribute in Web API parameter binding?
It binds complex types from the request body to the parameter.
How can you implement rate limiting in a Web API?
By tracking and limiting the number of requests from a single client within a specified time frame.
What is the role of the IActionResult interface in Web API?
It provides better control over HTTP response creation in action methods.
What is the difference between conventional routing and attribute routing in ASP.NET MVC?
Conventional routing uses route templates in configuration, while attribute routing defines routes directly on actions using attributes.
How can you generate URLs based on routes in ASP.NET MVC?
By using the UrlHelper class in views or controllers.
Explain the concept of route constraints in ASP.NET MVC.
Constraints restrict which requests match a particular route based on parameter values.
What is route template precedence in ASP.NET Core routing?
It determines how route templates are matched when multiple templates could potentially match a given URL.
How can you generate URLs in ASP.NET Core using the IUrlHelper interface?
You can use methods like IUrlHelper.Action() and IUrlHelper.RouteUrl() to generate URLs.
What is the purpose of route parameters in ASP.NET Core routing?
Route parameters capture values from the URL and make them available to route handlers.
Explain the concept of route constraints in ASP.NET Core routing.
Route constraints restrict which requests match a route template based on parameter values and regular expressions.
What is the difference between routing in ASP.NET Core MVC and ASP.NET Core Web API?
While MVC routing maps URLs to controller actions, Web API routing maps URLs to API controllers and actions.
How can you handle 404 errors (Not Found) in ASP.NET Core routing?
You can configure a fallback route or use middleware to catch unhandled requests.
What is attribute routing in ASP.NET Core?
Attribute routing allows you to define routes directly on action methods or controllers using attributes.
Explain the limitations of using cookies for state management.
Cookies have size limitations, are sent with every request, and can be tampered with.
How can you store complex objects in session state in ASP.NET?
By serializing the object and storing it in session variables.
What is the difference between TempData and ViewData in ASP.NET MVC?
TempData is used to persist data between requests, while ViewData is used to transfer data between a controller and a view.
How does the ASP.NET Core session state differ from the session state in ASP.NET?
In ASP.NET Core, the session state is stored outside the process, making it more suitable for load-balanced environments
What is the purpose of the ITempDataProvider interface in ASP.NET MVC?
It defines how TempData is stored and retrieved, allowing custom implementations.
What are distributed caches, and how can you use them for state management in ASP.NET Core?
Distributed caches store data in a shared location accessible to multiple instances, improving scalability and performance.
How can you manage cookies in ASP.NET Core applications?
By using the HttpContext.Request.Cookies and HttpContext.Response.Cookies properties
What is the role of the IHttpContextAccessor in ASP.NET Core session management?
It provides access to the current HttpContext, which is needed to interact with session state.
Explain the concept of TempData and Peek in ASP.NET MVC.
TempData stores data for a single subsequent request, while Peek lets you access data without removing it from TempData.
How does the concept of Razor Pages in ASP.NET Core affect state management?
Razor Pages promote a more cohesive architecture by merging the view and controller concerns, simplifying state management.
What are bearer tokens, and how are they used in authentication?
Bearer tokens are credentials that allow a client to access a protected resource on behalf of a user.
Explain the role of Claims in ASP.NET Core Identity.
Claims represent pieces of information about a user and are used for authorization decisions.
How does OAuth 2.0 differ from OAuth 1.0a?
OAuth 2.0 is more streamlined, with token-based authorization, while OAuth 1.0a used signatures for verification.
What is the purpose of OAuth scopes in authentication and authorization?
Scopes define the level of access a client application has to a user’s resources.
How can you implement social authentication (e.g., using Google or Facebook) in an ASP.NET Core application?
By configuring external authentication providers and handling the OAuth flow.
What is the purpose of the Authorize attribute in ASP.NET Core controllers?
It restricts access to actions based on user authentication and role membership.
Explain the differences between cookie-based authentication and token-based authentication.
Cookie-based authentication stores authentication information in cookies, while token-based authentication stores tokens (like JWT) in client-side storage.
How can you implement two-factor authentication in ASP.NET Core Identity?
By enabling 2FA options and setting up verification methods like SMS or email.
What is the role of Claims-based authorization in ASP.NET Core?
Claims-based authorization uses claims to determine whether a user is allowed to access a particular resource or action.
How can you secure WebSocket connections in ASP.NET Core applications?
By using authentication middleware and integrating WebSocket authentication.
What is the purpose of the UseExceptionHandler middleware in ASP.NET Core?
It catches unhandled exceptions and returns an appropriate error response.
How does the UseStaticFiles middleware work in ASP.NET Core?
It serves static files like HTML, CSS, and JavaScript from the wwwroot folder.
Explain the role of the UseRouting middleware in ASP.NET Core.
It sets up routing for incoming requests, determining which endpoint to execute.
What is the difference between UseAuthorization and UseAuthentication middleware in ASP.NET Core?
UseAuthentication sets up the authentication middleware, while UseAuthorization sets up the authorization middleware.
How can you create custom middleware to handle cross-cutting concerns in ASP.NET Core?
By implementing the IMiddleware interface and handling requests and responses.