Friday, 22 December 2017

ASP.NET MVC INTERVIEW QUESTIONS PART-2

1. What does MVC stand for?
Model-View-Controller.

2. What are three main components or aspects of MVC?
Model-View-Controller.

3. Which namespace is used for ASP.NET MVC? Or Which assembly is used to define the MVC framework?
System.Web.Mvc

4. What is the default view engine in ASP.NET MVC?
Web form (ASPX) and Razor View Engine.

5. Can we remove the default View Engine?
Yes, by using the following code
protected void Application_Start()  
{
      ViewEngines.Engines.Clear();  
}  

6. Can we have a Custom View Engine?
Yes, by implementing the IViewEngine interface or by inheriting from the Virtual Path Provider View Engine abstract class.

7. Can we use a third-party View Engine?
Yes, ASP.NET MVC can have Spark, NHaml, NDjango, Hasic, Brail, Bellevue, Sharp Tiles, String Template, Wing Beats, SharpDOM and so on third-party View Engine.

8. What are View Engines?
 View Engines are responsible for rendering the HTML from your views to the browser.

9. What is Razor Engine?
The Razor view engine is an advanced view engine from Microsoft, packaged with MVC 3. Razor uses a @ character instead of aspx's <% %> and Razor does not require you to explicitly close the code-back.
10. What is Scaffolding?
 Quickly generating a basic outline of your software that you can then edit and customize.

11. What is the name of Nuget scaffolding package for ASP.NET MVC scaffolding?
MvcScaffolding.

12. Can we share a view across multiple controllers?
Yes, it is possible to share a view across multiple controllers by putting a view into the shared folder.

13. What is unit testing?
The testing of every smallest testable block of code in an automated manner. Automation makes things more accurate, faster and reusable.

14. Is unit testing of MVC application possible without running the controller?
Yes, by the preceding definition.

15. Can you change the action method name?
Yes, we can change the action method name using the ActionName attribute. Now the action method will be called by the name defined by the ActionName attribute.
[ActionName("DoAction")]
public ActionResult DoSomething()  
{  
      /TODO:  
      return View();  
}   

16. How to prevent a controller method from being accessed by an URL?
By making the method private or protected but sometimes we need to keep this method public. This is where the Non-Action attribute is relevant.

17. What are the features of MVC5?
  • Scaffolding
  • ASP.NET Identity
  • One ASP.NET
  • Bootstrap
  • Attribute Routing
  • Filter Overrides
18. What are the various types of filters in an ASP.NET MVC application?
  • Authorization filters
  • Action filters
  • Result filters
  • Exception filters
19. If there is no match in the route table for the incoming request’s URL, Which error will result?
404 HTTP status code.

20. How to enable Attribute Routing?
By adding a Routes.MapMvcAttributeRoutes() method to the RegisterRoutes() method of the RouteConfig.cs file.

21. Which page is used to serve the common layout page for a group of views?
_ ViewStart.cshtml.

22. How can be render layout in ASP.NET MVC?
  • The _ViewStart.cshtml file in the Views folder provides the default Layout page.
  • We can also place the _ViewStart.cshtml file in the SubFolders of Views for providing a default layout to a specific directory.
  • defining the layout in a view on the top. @{Layout =”~/Views/Shared/_SchoolLayout.cshtml”;}
  • Layout from ActionResult.
23. In which version of MVC was the App_Start folder introduced?
MVC 4.

24. What is the name of the configuration files that the App_Start folder contains?
  • BundleConfig.cs
  • FilterConfig.cs
  • RouteConfig.cs
  • WebApiConfig.cs
25. Which does not require type casting among ViewData, ViewBag, TempData and Session?
ViewBag

26. What is the life of ViewData, ViewBag, TempData and Session in increasing order?
  • TempData: only until the target view is fully loaded.
  • ViewData: during the current request.
  • ViewBag: during the current request.
  • Session: for all requests.
27. From which class does ViewData, ViewBag, TempData and Session derive from?

  • TempData: TempDataDictionary class
  • ViewData: ViewDataDictionary class
  • ViewBag: takes advantage of the new dynamic features in C# 4.0
  • Session: HttpSessionState class
28. Which class is the base class of all action results?
ActionResult class.

29. Why do we need server-side validation when we have client-side validation?
The user can disable a script in his browser and bypass client-side validation. So, we need server-side validation to protect from such un-validated data.

30. Which property is used to determine an error in Model State?
ModelState.IsValid property.
If there is any error then ModelState.IsValid returns false. If there is no error it will return true.

31. What is latency?
The amount of time it takes for the host server to receive, process, and deliver on a request
for a page resource (images, CSS files, and so on).

32. Why do we use CDN?
It solves latency problems.
  • A CDN caches static resources in distributed servers across a region or worldwide.
  • Thereby bringing resources closer to users and reducing round trip time.
33. In which version of ASP.NET MVC was bundling and minification techniques introduced?
ASP.NET MVC4 and .NET Framework 4.5.

34. What is bumdling and minification in ASP.NET MVC?
Bundling: It bundles multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files mean fewer HTTP requests that can improve first page load performance.
Minification: Minification does a variety of code optimizations for scripts or CSS, such as removing unnecessary white space and comments and shortening variable names to one character.

35. What is the order of execution of filters?
  • Authentication filters
  • Authorization filters
  • Action filters
  • Result filters
36. Various ways of implementing Dependency Injection.
  • Constructor Injection
  • Property Injection
  • Method Injection
37. Advantage of Dependency Injection.
  • Improves Application Testing
  • Improves Code Maintainability
  • Reduces Class Coupling
  • Increases code reusing
38. What is Test Driven Development?
TDD is a methodology in which we write tests first then write code.

39. What is Area?
Area allows us to organize models, views and controllers into separate functional sections of the application.

40. Can be use bundling and minification in ASP.NET MVC3?
Yes, by using the System.Web.Optimization class.   

41) what is the use of action filters in an MVC application?
Action Filters allow us to add pre-action and post-action behavior to controller action methods.

42) if I have multiple filters implanted, what is the order in which these filters get executed?
1. Authorization filters
2. Action filters
3. Response filters
4. Exception filters

43) what are the different types of filters, in an asp.net mvc application?
1. Authorization filters
2. Action filters
3. Result filters
4. Exception filters

44) give an example for Authorization filters in an asp.net mvc application?
1. RequireHttpsAttribute
2. AuthorizeAttribute

45) which filter executes first in an asp.net mvc application?
Authorization filter

46) what are the levels at which filters can be applied in an asp.net mvc application?
1. Action Method
2. Controller
3. Application
[b]Is it possible to create a custom filter?[/b]
Yes

47) what filters are executed in the end?
Exception Filters

48) is it possible to cancel filter execution?
Yes

49) what type of filter does OutputCacheAttribute class represents?
Result Filter

50) what are the 2 popular asp.net mvc view engines?
1. Razor
2. .aspx

51) what symbol would you use to denote, the start of a code block in razor views?
@

52) what symbol would you use to denote, the start of a code block in aspx views?
<%= %>

53) in razor syntax, what is the escape sequence character for @ symbol?
The escape sequence character for @ symbol, is another @ symbol

54) when using razor views, do you have to take any special steps to proctect your asp.net mvc application from cross site scripting (XSS) attacks?
No, by default content emitted using a @ block is automatically HTML encoded to protect from cross site scripting (XSS) attacks.

55) when using aspx view engine, to have a consistent look and feel, across all pages of the application, we can make use of asp.net master pages. What is asp.net master pages equivalent, when using razor views?
To have a consistent look and feel when using razor views, we can make use of layout pages. Layout pages, reside in the shared folder, and are named as _Layout.cshtml

56) what are sections?
Layout pages, can define sections, which can then be overridden by specific views making use of the layout. Defining and overriding sections is optional.

57) what are the file extensions for razor views?
1. .cshtml - If the programming language is C#
2. .vbhtml - If the programming language is VB

58) how do you specify comments using razor syntax?
Razor syntax makes use of @* to indicate the beginning of a comment and *@ to indicate the end. An example is shown below.
@* this is a Comment *@      


No comments: