Thursday, November 23, 2023

ASP.NET Core MVC || MVC

 Here are some additional ASP.NET Core MVC interview questions:

Q1. What is routing in ASP.NET Core MVC and how does it work?

A1. Routing is used to map incoming HTTP requests to particular MVC controller actions. The Configure() method in Startup.cs file adds endpoint routing middleware that maps request URLs to routing templates defined using attributes like [Route] and controllers.

Q2. How do you manage state in an ASP.NET Core application?

A2. ASP.NET Core is stateless by default. To manage state, we can use sessions by adding session middleware. State can also be stored in databases or external state cache like Redis. 

Q3. What is the file-based authorization policy in ASP.NET Core?

A3. It allows authorizing users against user roles defined in a JSON file rather than in app code. We create a JSON file mapping users to roles and configure the Authorization service to use the policy in Startup.cs.

Q4. How are model bindings used in ASP.NET Core MVC?

A4. Model binding automatically maps form data and route data from an HTTP request to parameters in a controller action. We just need to define the parameter name same as input field in a form or route parameter.

Q5. What is view composition in ASP.NET Core MVC?

A5. Building a view using both a main view and partial views defined in separate Razor view files. The main view can render HTML sections defined in partial views using @await Html.PartialAsync() method.

Q6. How do you serve static files in ASP.NET Core web apps?

A6. Using built-in middleware by configuring it through methods like app.UseStaticFiles() in Startup.cs. We define a static file path, set caching headers for static files etc.

Q7. How do you implement logging in ASP.NET Core apps?

A7. Using ILogger interface injected into classes needing logging. Log messages written through ILogger will be directed to logging providers configured in Startup - like console, debug, file, Azure App Insights etc.