InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What are the advantages of using Scaffolding in ASP.NET MVC? |
|
Answer» Scaffolding is a code generation FRAMEWORK used for ASP.NET web applications that will be helpful in effectively generating the code for CRUD(CREATE, Read, Update, and Delete) operations against your database. The Advantages of Scaffolding are as follows:
|
|
| 2. |
How to implement Forms authentication in ASP.NET MVC? |
|
Answer» AUTHENTICATION means providing access to the user for a particular service through verification of his/her identity using his/her credentials such as email-id and password or username and password. It will make sure that the correct user will be authenticated or logged in for a particular service and the right service will be GIVEN to the specific user depending on their role. Forms authentication in ASP.NET will be done after the completion of IIS(Internet Information Services) authentication. It is possible to configure forms authentication with the help of the forms element in the file web.config of your application. The forms authentication default attribute values are given below: <system.web> <authenticationmode="Forms"> <formsloginUrl="Login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" /> </authentication></system.web>The FormsAuthentication class will automatically create the authentication cookie when it calls the methods RedirectFromLoginPage() or SetAuthCookie(). The value of an authentication cookie will be having the STRING representation for the signed and encrypted FormsAuthenticationTicket object. |
|
| 3. |
Explain state management in ASP.NET MVC. |
|
Answer» The collection of input values(example: city, mobile number, e-mail id, etc.) of a specific web page is called as state of that page. By default, it is not possible to retain the values(states) provided on a single page of a web APPLICATION, when you navigate to another web page. This nature of a web page is known as stateless behaviour. You can make use of different state management techniques for retaining the values(state) across the web pages. The below-given COMMON state management techniques will be supported by the ASP.NET MVC:
|
|
| 4. |
Explain TDD(Test Driven Development) in ASP.NET MVC. |
|
Answer» TDD or Test DRIVEN DEVELOPMENT is an approach where a test will be written before the completion of production code writing for the purpose of refactoring and fulfilling the test. TDD is also known as the Red-Green-Refactor method of development. The Workflow of TDD is given below:
|
|
| 5. |
Explain about TempData in ASP.NET MVC. |
|
Answer» TempData is a dictionary object useful for the temporary storage of data. It is an instance of the Controller base class. It is useful in storing the data for the duration of an HTTP request, or we can SAY that it can store live data between two consecutive REQUESTS of HTTP. It is also useful in passing the state between ACTION methods. TempData can be used only with the subsequent and current requests. It will make use of a session variable for storing the data. TempData needs typecasting during data retrieval. Example: In the below-given code, employee details will be TEMPORARILY stored by TempData. public ActionResult FirstRequest(){ LIST<string> TempDataDemo = new List<string>(); TempDataDemo.Add("Harish"); TempDataDemo.Add("Nagesh"); TempDataDemo.Add("Rakshith"); TempData["EmployeeName"] = TempDataDemo; return View();}public ActionResult ConsecutiveRequest(){ List<string> modelData = TempData["EmployeeName"] as List<string> ; TempData.Keep(); return View(modelData);} |
|
| 6. |
What is Razor View Engine in ASP.NET MVC? |
|
Answer» Razor View Engine in ASP.NET MVC is a simple-syntax view engine used for creating a view of an application. It was released in JANUARY 2011 for Microsoft Visual Studio as a part of ASP.NET MVC 3. Razor will make USE of C# syntax for the PURPOSE of embedding code in a page without the usage of ASP.NET delimiters: <%= %>. The file extension of Razor is “cshtml” for the C# PROGRAMMING language. It supports Test Driven Development(TDD) as it will not be dependent on the System.Web.UI.Page class. |
|
| 7. |
What is View Engine? |
|
Answer» A View Engine is an MVC subsystem and has its own MARKUP SYNTAX. It will convert the template from the server-side into HTML markup and then render it to the browser. In the BEGINNING, ASP.NET MVC was having a single view engine i.e., web forms(ASPX), from ASP.NET MVC 3 a Razor view engine Razor has been INTRODUCED. You can also make use of other view engines such as NHaml, Spark, etc., in ASP.NET MVC. |
|
| 8. |
What are bundling and minification in ASP.NET MVC? |
|
Answer» Bundling and minification are two techniques used for your WEB application in the ASP.NET MVC framework for improving the performance of the PAGE load. Bundling will combine several files into a single file. Minification will perform different TYPES of code optimizations to CSS and scripts, which will result in smaller payloads. With the help of bundling and minification, we can improve the performance of load time by reducing the requested ASSETS(like JavaScript and CSS files) size and by reducing the number of requests to the server. |
|
| 9. |
What is ViewBag and ViewData in ASP.NET MVC? |
|
Answer» ViewBag:
Controller: public CLASS ExampleController : Controller{ public ActionResult Index() { ViewBag.Message = "This is about ViewBag ASP.NET MVC!!"; return View(); }}View: <html><head> <meta name="viewport" content="width=device-width"/> <title>IndexDisplay</title></head><body> <div> @ViewBag.Message </div></body></html>ViewData:
Controller: public class ExampleController : Controller{ public ActionResult Index() { ViewData["Message"] = "This is about ViewData in ASP.NET MVC!!!"; return View(); }}View: <html><head> <meta name="viewport" content="width=device-width"/> <title>Index</title></head><body> <div> @ViewData["Message"] </div></body></html> |
|
| 10. |
What are the Advantages of ASP.NET MVC? |
|
Answer» Following are a few advantages of ASP.NET MVC:
|
|
| 11. |
What are Action filters in ASP.NET MVC? |
|
Answer» ACTION filters are the additional ATTRIBUTES in the ASP.NET MVC framework, that we can apply to either a section of the CONTROLLER or to the entire controller for modifying the approach in which action will be executed. Action filter attributes are SAID to be special .NET classes as they are derived from the System.Attribute class and they can be ATTACHED to classes, properties, methods, and fields. The following action filters are provided by ASP.NET MVC:
The below-given code will apply Output cache filter on an ActionFilterExampleController (Here, ActionFilterExampleController is just used as an example, You can apply action filters on any of the controllers). It specifies that the return value should be cached for 20 seconds. public class ActionFilterExampleController: Controller{ [HttpGet] OutputCache(Duration = 20)] public string Index() { return DateTime.Now.ToString("T"); }} |
|
| 12. |
Explain about ASP.NET MVC filters. |
|
Answer» The five types of Filters in ASP.NET MVC and order of their execution are as follows:
It is possible to override the methods in your controller class if you wish to do so. |
|
| 13. |
What is JsonResultType (JavaScript Object Notation Result Type) in ASP.NET MVC? |
|
Answer» Action methods on controllers will return JsonResult that will be used WITHIN an AJAX application. From the “ActionResult” abstract CLASS, this JsonResult class will be inherited. Here Json will be supplied with a SINGLE argument that must be serializable. The JSONResult OBJECT will SERIALIZE the specified object into JSON format. Example: public JsonResult JsonResultExample(){ return Json("Hello InterviewBit!!");} |
|
| 14. |
What is Area in ASP.NET MVC? |
|
Answer» The area will permit to divide the larger application into smaller units where every UNIT will have an MVC FOLDER structure SEPARATELY, exactly like the default MVC folder structure. Consider an example of a large enterprise application that might have different modules such as HR, finance, ADMIN, marketing, etc. So for all these modules, an Area can have a separate MVC folder structure. |
|
| 15. |
What is the Action Method in MVC? |
|
Answer» The action methods in ASP.NET MVC will help for executing the request and generating a response to it. Every PUBLIC method of the MVC Controller is considered an action method. If you want the public method to act as a non-action method, then it is possible to decorate the action method by using the ATTRIBUTE “NonAction”. This will restrict an action method from rendering on the browser. A few points to be remembered while working with action methods are:
It is possible to create action methods that will return an object of any type like an integer, a Boolean value, or a string. These return types will be wrapped in an ActionResult type that is appropriate before they are being RENDERED onto the response stream. Any return type that is not an action result will be converted into a string by the ASP.NET MVC and the string will be rendered into the browser. We can create a simple controller as PER the code given below: public class HomeController : Controller { public ActionResult HelloInterviewbit() { ViewData["SayInterviewbit"] = "Interviewbit"; return View(); } public string SayInterviewbit() { return "This is from 'SayInterviewbit'."; } }We must create a view for running SayInterviewbit() as it will return the View as views\home\SayInterviewbit.cshtml. For executing the second action method, it does not require the creation of a view. In the browser, the string will be rendered. It is possible for an void public method to act as an action method. This implies that any public method can BECOME an action method. |
|
| 16. |
When to use Attribute Routing? |
|
Answer» By using attribute routing, you can easily define some of the URI patterns that are most COMMON in RESTful APIs. For example, resources will usually have child resources such as movies have actors, Clients will have orders, books have authors, etc. So it’s obvious to create URIs that reflect these kinds of relations such as /clients/1/orders. It is difficult to create these kinds of URIs using convention-based routing. With the help of attribute routing, it becomes easier for defining a route to this URI. You need to ADD an attribute to the controller action as GIVEN below: [Route("clients/{cId}/orders")]public IEnumerable<Order> ObtainOrdersByClient(int cId){ //Statements}To enable attribute routing in ASP.NET MVC 5 application, you need to add a call to the method routes.MapMvcAttributeRoutes() WITHIN the RegisterRoutes() method of RouteConfig.cs file. |
|
| 17. |
What is Routing in ASP.NET MVC? |
|
Answer» Routing in ASP.NET MVC is a pattern matching system that maps the incoming requests from the BROWSER to specified actions of the MVC controller. When the application of ASP.NET MVC gets started, it registers one or multiple patterns with the framework route table so that it can inform the routing engine that what has to be done with the requests that are matching with those patterns. When a request is received by the routing engine during runtime, it matches that URL of the request against its registered URL patterns and PROVIDES the response based on a pattern match. The URL pattern in routing will be considered based on the domain name part in the URL. For example, the URL pattern "{controller}/{action}/{id}" will look similar to localhost:1234/{controller}/{action}/{id}. Anything that comes after the"localhost:1234/" will be considered as the name of the controller. In the same manner, anything that comes after the controller name will be considered as the name of the action and then comes the id parameter value. If the URL has nothing after the domain name, then the request will be handled by the default controller and action method. For example, the URL http://localhost:1234 will be handled by the Index() method and by the HomeController as per the default parameter configuration. The below-given route table will show which CONTROLLERS, Action methods, and Id parameters will be HANDLING the various URLs according to the above-provided default route. The below figure shows request processing by routing engine and response sent by it. It provides a response based on URL match in the route table. When the URL of the request matches any of the route patterns that are registered in the route table then the request will be forwarded by the routing engine to the suitable handler for that request. Later the route will be processed and obtain a view on the UI. When the URL of the request doesn’t match with any of the route patterns that are registered, the routing engine will indicate that it can’t determine how to do request handling by returning an HTTP STATUS code 404. |
|
| 18. |
Explain about ASP.NET MVC 5. |
|
Answer» The ASP.NET MVC 5 FRAMEWORK is the NEWEST evolution of the ASP.NET web platform by Microsoft. A HIGHLY effective programming model will be provided by ASP.MVC 5, which promotes powerful extensibility, cleaner code architecture, test-driven development, in addition to all the ASP.NET BENEFITS. |
|
| 19. |
What are the three main components of an ASP.NET MVC application? |
|
Answer» In the below-given figure, you can see THREE main components of the MVC architecture in ASP.NET and interaction among them. The 3 main components of an ASP.NET MVC application are model, VIEW, and controller.
|
|
| 20. |
What is ASP.NET MVC? |
|
Answer» ASP.NET MVC is a LIGHTWEIGHT framework for developing WEB and mobile applications. This framework divides an application into the three MAIN components that make up MVC(Model, View, and Controller). In this MVC pattern for WEBSITES, action performance or data retrieval will be DONE when requests will be sent to a Controller that is in co-ordinance with the Model for doing such tasks. The model will retrieve the data and also store it in the database. The Controller selects the View for displaying and provides it along with the Model. The final page will be rendered by the View based on the data present in the Model. MVC along with ASP.NET will give you a powerful and patterns-based way of developing dynamic websites as it enables a separation of concerns. |
|