Você está na página 1de 5

Articles from Jinal Desai .

NET
ASP.NET MVC 4 New Features Interview Questions
2013-06-27 06:06:40 Jinal Desai

1. What is main focus of ASP.NET MVC 4? Ans. The main focus of ASP.NET MVC 4 is making it easier to develop mobile web applications. Other than mobile web applications its focus is also on better HTML5 support and making ASP.NET MVC web application cloud ready. Using new features of ASP.NET MVC 4 you can develop web applications that can work well across different mobile devices and desktop web browsers. 2. What is ASP.NET Web API? Ans. ASP.NET Web API is a framework for building and consuming HTTP Services. It supports wide range of clients including browsers and mobile devices. It is a great platform for developing RESTful services since it talks HTTP. 3. You can also develop RESTful services using WCF, then why this new framework Web API? Ans. Yes we can still develop RESTful services with WCF, but there are two things that prompt users to use ASP.NET Web API over WCF for development of RESTful services. First one is ASP.NET Web API is included in ASP.NET MVC which obviously increases TDD approach in the development of RESTful services. Second one is for developing RESTful services in WCF you still needs lot of configurations, URI templates, contracts and endpoints which developing RESTful services using ASP.NET Web API is simple. 4. What are the enhancements done in default project template of ASP.NET MVC 4? Ans. The enhanced default project template is modern-looking. Along with cosmetic enhancements, it also employs adaptive rendering to look nice in both desktop and mobile browsers without need of any kind of additional customization. 5. Why separate mobile project template while you can render your web application in mobile without additional customization? Ans. The mobile project template touch-optimized UI using jQuery.Mobile.MVC NuGet Package for smart phones and tablets. 6. What is Display Modes? Ans. Display Modes is new feature provided in ASP.NET MVC 4. It lets an application select views depending on the browser which is making request. For example, if a desktop browser requests home page of an application it will return Views\Home\Index.cshtml view and if a mobile browser requests home page it will return Views\Home\Index.mobile.cshtml view. 7. Does ASP.NET MVC 4 supports Windows Azure SDK? Ans. Yes, ASP.NET MVC 4 supports Windows Azure SDK version 1.6 or higher.

8. What is Bundling and Minification feature provided in ASP.NET MVC 4? Ans. It reduces number of HTTP requests that a web page needs to make. Bundling and Minification combines individual files into single, bundled file for scripts and CSS and then reduce the overall size by minifying the contents of the bundle. 9. While developing application using ASP.NET MVC 4, I want to provide authentication using popular sites like Facebook or twitter into my web application, is it possible in ASP.NET MVC 4? Ans. Yes, using DotNetOpenAuth library we can provide authentication using OAuth or OpenID providers. In ASP.NET MVC 4 Internet project template includes this library. 10. Whats the difference between Empty MVC Project template in ASP.NET MVC 3 and ASP.NET MVC 4? Ans. The ASP.NET MVC 4 Empty project template is really empty. It does not contain any css and js files as compared to previous Empty project template, which contains all these files. 11. What are the main features of ASP.NET MVC used by ASP.NET Web API? Ans. Routing: ASP.NET Web API uses same convention for configuration mapping that ASP.NET MVC provides. Model Binding and Validation: ASP.NET Web API uses same model binding functionality, but tailored to HTTP specific context related operations only. Filters: The ASP.NET Web API uses lots of filters built-in MVC. Unit Testing: Now its based on MVC, truly unit testable. 12. If I want to create resource oriented services that can use full features of HTTP like cache control for browsers, use URI templates to include Task URIs in your responses, versioning and concurrancy using ETags, pass various content types such as images, documents, HTML pages etc. then which is preferred for development of services, WCF or Web API? Ans. In such scenario Web API would be preferred choice. Using Web APIs we can develop services which utilizes full features of HTTP. 13. Suppose I want to develop services which supports special scenarios like one way messaging, duplex communication, message queues, ete then which is the best way to develop services, WCF or Web API? Ans. In this scenario WCF suits the requirement. WCF provides all kine of messaging facility. 14. Now, if I want to create services which are exposed over various transport channels like TCP, Named Pipe or even UDP. I also want the support of HTTP transport channel when other transport channels are unavailable then which is the preferred way, WCF or Web API and why? Ans. For such scenario WCF is preferred way for development of services because WCF support almost all kind of transport mechanism and we need to expose SOAP-based and WebHTTP-based bindings.

15. What is the difference between asynchronous controller implementation between ASP.NET MVC 3 and ASP.NET MVC 4? Can you explain in detail? Ans. There is large difference between the working and implementation mechanism between ASP.NET MVC 3 and ASP.NET MVC 4. In ASP.NET MVC 3, to implement asynchronous controller/methods you need to derive controller from AsyncController rather than from plain Controller class. You need to create two action methods rather than one. Fist with suffix Async keyword and second with Completed suffix. The method which initiated asynchronous process must end with Async and the method which is invoked when the asynchronous process finishes must end with Completed. Following is example showing the same. //Synchronous Implementation public class SynchronousTestController : Controller { public ActionResult Index() { method1(); method2(); return View(); } } //Asynchronous Implementation in ASP.NET MVC 3 public class AsynchronousTestController : AsyncController { public void IndexAsync() { method1(); method2(); } public ActionResult IndexCompleted() { return View("Index"); } } The ASP.NET MVC 4 Controller class in combination .NET 4.5 enables you to write asynchronous action methods that return an object of type Task. The .NET Framework 4 introduced an asynchronous programming concept referred to as a Task and ASP.NET MVC 4 supports Task. The .NET Framework 4.5 builds on this asynchronous support with the await and async keywords that make working with Task objects much less complex than previous asynchronous approaches. The await keyword is syntactical shorthand for indicating that a piece of code should asynchronously wait on some other piece of code. The async keyword represents a hint that you can use to mark methods as task-based asynchronous methods. To implement asynchronous action method in ASP.NET MVC 4 we do no need to derive our controller class from AsyncController, async and await in cooperation

with Task will do the magic. To mark the action method asynchronous use async in method signature. To wait for the other method to finish use await and to call multiple parallel methods use Task. The asynchronous method will return Task instead of plain ActionResult. public class AsyncronousTestController : Controller { public async Task<ActionResult> IndexAsync() { //if single method //await method(); //if multiple methods await Task.WhenAll(method1(), method2()); return View("Index"); } } Here the await keyword does not block the thread execution until the task is complete. It signs up the rest of the method as a callback on the task, and immediately returns. When the awaited task eventually completes, it will invoke that callback and thus resume the execution of the method right where it left off. 16. Can you tell us some guidelines for when to use synchronous and when to use asynchronous approach? Ans. In following situations synchronous approach is more suited. 1. The operations are simple or short-running. 2. Simplicity is more important than efficiency. 3. The operations are primarily CPU operations instead of operations that involve extensive disk or network overhead. Using asynchronous action methods on CPU-bound operations provides no benefits and results in more overhead. For asynchronous approach some of the guidelines are 1. Youre calling services that can be consumed through asynchronous methods, and youre using .NET 4.5 or higher. 2. The operations are network-bound or I/O-bound instead of CPU-bound. 3. Parallelism is more important than simplicity of code. 4. You want to provide a mechanism that lets users cancel a long-running request. 5. When the benefit of switching threads out weights the cost of the context switch. In general, you should make a method asynchronous if the synchronous method waits on the ASP.NET request thread while doing no work. By making the call asynchronous, the ASP.NET request thread is not stalled doing no work while it waits for the web service request to complete. 6. Testing shows that the blocking operations are a bottleneck in site performance and that IIS can service more requests by using asynchronous methods for these blocking calls.

17. Which latest version of Entity Framework is included by ASP.NET MVC 4? What is the advantage of it? Ans. ASP.NET MVC 4 is included Entity Framework 5. The main advantage of Entity Framework 5 is its new feature called database migration. It enables you to easily evolve your database schema using a code-focused migration while preserving the data in the database. 18. What is ASP.NET MVC 4 recipe? Can you explore something on recipes? Ans. In technical language ASP.NET MVC 4 recipe is nothing but a dialog box that is delivered via NuGet with associated UI and code used to automate specific task. Its like GUI for NuGet Package Manager. Recipes are set of assemblies which are loaded dynamically by Managed Extensibility Framework (MEF). MEF provides plugin model for applications. The main use of recipes are to automate development task, tasks that are encapsulated into recipes and used over and over again. For example, adding ajax grid to view or manipulating multiple areas of the application can be automated using ASP.NET MVC 4 recipes. 18. What are the provisions for real time communication in ASP.NET MVC 4? Ans. ASP.NET MVC 4 supports WebSockets along with the new open source framework SignalR which allows to set up real time multi-user communication through open TCP sockets. 19. What is the enhancement provided related to custom controller in ASP.NET MVC 4? Ans. In ASP.NET MVC 4 you can place custom controller to custom locations. In ASP.NET MVC 3 you can only place custom controllers inside the Controllers folder.

Você também pode gostar