Thursday, November 23, 2023

ASP.NET Core MVC || Core

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

Q1. What is Razor in ASP.NET Core MVC?

A1. Razor is a view engine for rendering views. It allows you to mix C# or Visual Basic code with HTML markup in Razor View (.cshtml file) to build UI.

Q2. What are Tag Helpers in ASP.NET Core MVC?

A2. Tag Helpers allow you to add server-side logic to existing HTML tags using attributes designed for that specific tag. They are processed on the server before any client-side frameworks like React or Angular get them.

Q3. How do you handle security in ASP.NET Core MVC applications?  

A3. Some ways to handle security include:

- Authentication - Identity library, Azure AD, OAuth/OpenID 

- Authorization - Role-based or policy-based authorization

- HTTPS

- CORS

- Input validation

Q4. What is caching? How can we implement caching in ASP.NET Core?

A4. Caching is storing data/page output temporarily so that future requests can be served faster. We can implement in-memory caching using IMemoryCache interface or a distributed cache like Redis. The data has an expiration period and gets invalidated after that.

Q5. How do you configure linking between MVC views and actions?

A5. Using attribute routing to provide named routes like [Route("[controller]/[action]")]. We generate links using these named routes with Url.Action() or <a asp-action="">

Q6. What is JSON serialization and how do you implement it in ASP.NET Core?

A6. Converting a .NET object to JSON format. We can use JsonSerializer class or in ASP.NET Core, adding [ApiController] attribute handles serialization automatically using System.Text.Json library.

Q7. What is view injection in ASP.NET Core MVC?

A7. Dependency injecting a view component into a view via the @inject directive so that we can call methods on that injected class directly from the view.