What are the 3 main components of an ASP.NET MVC application?
1. M - Model
2. V - View
3. C - Controller
What is the ‘page lifecycle’ of an ASP.NET MVC?
Following process are performed by ASP.Net MVC page:
1) App initialization
2) Routing
3) Instantiate and execute controller
4) Locate and invoke controller action
5) Instantiate and render view
Request flow handles the request from the clients and passes it to the server. The Request flow is as follows:
-Request is being taken from User to controller.
-Controller processes the request from the user and creates a data Model of that particular request.
-Data model that is being created is then passed to View that handles the frontend or the design.
-View then transforms the Data Model by using its own functions in an appropriate output format.
-The output format that is being given by the View is then gets rendered to the Browser and the View will be seen by the user.
-App_Data: this contains the database files like local instance SQL server express database files.
-Content: it contains the static content that is used for the web application building like CSS, images, etc.
-Controller: it contains the controller classes that are used in ASP.NET MVC architecture.
-Models: it consists of the model classes that are used to interact with the content and go in sync with the MVC architecture of the ASP.NET.
-Scripts: JavaScript files that include the AJAX library and jQuery script files.
-Views: it contains the frontend view that will be seen after the model is rendered.
-App initialization: in this the initiation of the application takes place that allow the application to interact the server and start to run the components.
-Routing: in this the messages are routed to the server for making the delivery of the request easier.
-Instantiate and execute controller: in this way the controller handles the request and passes it on to display the output or replies to the request.
-Locate and invoke controller action: The actions allow the controller to be located correctly and it invokes the correct action that has to be taken on the applications.
-Instantiate and render view: this helps in view the result of the application that is being built.
Can you describe ASP.NET MVC Request Life Cycle?
Following are the steps that are executed in ASP.NET MVC Request Life Cycle.
1. Application first receives the request and looks up Route object in RouteTable collection. Then the RouteData object is created.
2. Then RequestContext instance is created.
3. MvcHandler and pass RequestContext to handler is created.
4. Then IControllerFactory from RequestContext is identified.
5. Then the object of class that implements ControllerBase is created.
6. MyController.Execute method is called.
7. Then ControllerActionInvoker finds the action to invoke on the controller and executes that action on the controller and by calling the model associated view returns.
In which assembly is the MVC framework defined?
System.Web.Mvc
Is it possible to combine ASP.NET webforms and ASP.MVC and develop a single web application?
Yes, it is possible to combine ASP.NET webforms and ASP.MVC and develop a single web application.
What does Model, View and Controller represent in an MVC application?
Model: Model represents the application data domain. In short the applications business logic is contained with in the model.
View: Views represent the user interface, with which the end users interact. In short the all the user interface logic is contained with in the UI.
Controller: Controller is the component that responds to user actions. Based on the user actions, the respective controller, work with the model, and selects a view to render that displays the user interface. The user input logic is contained with in the controller.
What is the greatest advantage of using asp.net mvc over asp.net webforms?
It is difficult to unit test UI with webforms, where views in mvc can be very easily unit tested.
Which approach provides better support for test driven development - ASP.NET MVC or ASP.NET Webforms?
ASP.NET MVC
What are the advantages of ASP.NET MVC?
1. Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested.
2. Complex applications can be easily managed
3. Seperation of concerns. Different aspects of the application can be divided into Model, View and Controller.
4. ASP.NET MVC views are light weight, as they donot use viewstate.
Is it possible to unit test an MVC application without running the controllers in an ASP.NET process?
Yes, all the features in an asp.net MVC application are interface based and hence mocking is much easier. So, we don't have to run the controllers in an ASP.NET process for unit testing.
Is it possible to share a view across multiple controllers?
Yes, put the view into the shared folder. This will automatically make the view available across multiple controllers.
What is the role of a controller in an MVC application?
The controller responds to user interactions, with the application, by selecting the action method to execute and alse selecting the view to render.
Where are the routing rules defined in an asp.net MVC application?
In Application_Start event in Global.asax
Name a few different return types of a controller action method?
The following are just a few return types of a controller action method. In general an action method can return an instance of a any class that derives from ActionResult class.
1. ViewResult
2. JavaScriptResult
3. RedirectResult
4. ContentResult
5. JsonResult
What is the significance of NonActionAttribute?
In general, all public methods of a controller class are treated as action methods. If you want prevent this default behaviour, just decorate the public method with NonActionAttribute.
What is the significance of ASP.NET routing?
ASP.NET MVC uses ASP.NET routing, to map incoming browser requests to controller action methods. ASP.NET Routing makes use of route table. Route table is created when your web application first starts. The route table is present in the Global.asax file.
What are the 3 segments of the default route, that is present in an ASP.NET MVC application?
1st Segment - Controller Name
2nd Segment - Action Method Name
3rd Segment - Parameter that is passed to the action method
Example: http://pragimtech.com/Customer/Details/5
Controller Name = Customer
Action Method Name = Details
Parameter Id = 5
ASP.NET MVC application, makes use of settings at 2 places for routing to work correctly. What are these 2 places?
1. Web.Config File : ASP.NET routing has to be enabled here.
2. Global.asax File : The Route table is created in the application Start event handler, of the Global.asax file.
What is the adavantage of using ASP.NET routing?
In an ASP.NET web application that does not make use of routing, an incoming browser request should map to a physical file. If the file does not exist, we get page not found error.
An ASP.NET web application that does make use of routing, makes use of URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users.
-URL routing system is used to map the application and its routing information gets passed to right controller and action method.
-URL routing system processes and executes the method to run the application without using many designed rules.
-It is used to construct the outgoing URLs that can be used to handle the actions that have the ability to map both incoming and outgoing URLs that adds more flexibility to the application code.
-It follows the rules to execute the application globally and handle the logic that is required for the application.
What are the 3 things that are needed to specify a route?
1. URL Pattern - You can include placeholders in a URL pattern so that variable data can be passed to the request handler without requiring a query string.
2. Handler - The handler can be a physical file such as an .aspx file or a controller class.
3. Name for the Route - Name is optional.
Is the following route definition a valid route definition?
{controller}{action}/{id}
No, the above definition is not a valid route definition, because there is no literal value or delimiter between the placeholders. Therefore, routing cannot determine where to separate the value for the controller placeholder from the value for the action placeholder.
What is the use of the following default route?
{resource}.axd/{*pathInfo}
This route definition, prevent requests for the Web resource files such as WebResource.axd or ScriptResource.axd from being passed to a controller.
What is the difference between adding routes, to a webforms application and to an mvc application?
To add routes to a webforms application, we use MapPageRoute() method of the RouteCollection class, where as to add routes to an MVC application we use MapRoute() method.
How do you handle variable number of segments in a route definition?
Use a route with a catch-all parameter. An example is shown below. * is referred to as catch-all parameter.
controller/{action}/{*parametervalues}
What are the 2 ways of adding constraints to a route?
1. Use regular expressions
2. Use an object that implements IRouteConstraint interface
Give 2 examples for scenarios when routing is not applied?
1. A Physical File is Found that Matches the URL Pattern - This default behaviour can be overriden by setting the RouteExistingFiles property of the RouteCollection object to true.
2. Routing Is Explicitly Disabled for a URL Pattern - Use the RouteCollection.Ignore() method to prevent routing from handling certain requests.
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.
If I have multiple filters impleted, what is the order in which these filters get executed?
1. Authorization filters
2. Action filters
3. Response filters
4. Exception filters
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
Give an example for Authorization filters in an asp.net mvc application?
1. RequireHttpsAttribute
2. AuthorizeAttribute
Which filter executes first in an asp.net mvc application?
Authorization filter
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
What filters are executed in the end?
Exception Filters
Is it possible to cancel filter execution?
Yes
What type of filter does OutputCacheAttribute class represents?
Result Filter
What are the 2 popular asp.net mvc view engines?
1. Razor
2. .aspx
What symbol would you use to denote, the start of a code block in razor views?
@
What symbol would you use to denote, the start of a code block in aspx views?
<%= %>
In razor syntax, what is the escape sequence character for @ symbol?
The escape sequence character for @ symbol, is another @ symbol
-For example if you have a method in the Employee controller with the following implementation:
public ActionResult GetEmployees()
{
Return view();
}
-Then we creat a view named GetEmployees in the Employee folder inside of Views. This is not mandatory, however, and we can return give a alternate name to the views passing the name of the view as a string as below:
public ActionResult GetEmployees ()
{
Return view(“EmployeeDetails”);
}
-By using asynchronous controller we can optimize the performance of web server by avoiding the usage of extra resources once a request is processed.
-The AsyncController class is more useful for the calls of web service which takes long time to process.
How to create an asynchronous controller?
The AsyncController class enables you to write asynchronous action methods. You can use asynchronous action methods for long-running, non-CPU bound requests. This avoids blocking the Web server from performing work while the request is being processed. A typical use for the AsyncController class is long-running Web service calls.
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.
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
What are sections?
Layout pages, can define sections, which can then be overriden by specific views making use of the layout. Defining and overriding sections is optional.
What are the file extensions for razor views?
1. .cshtml - If the programming lanugaue is C#
2. .vbhtml - If the programming lanugaue is VB
How do you specify comments using razor syntax?
Razor syntax makes use of @* to indicate the begining of a comment and *@ to indicate the end. An example is shown below.
@* This is a Comment *@
How to intermix ASP.NET Web Form and MVC?
Adding
MVC Interview questions Link
http://www.dotnetobject.com/Thread-MVC-Interview-Questions-Answers
http://www.wiziq.com/online-tests/32130-asp-net-mvc-interview-questions
http://www.mindstick.com/Interviewer/QuestionPage.aspx?topicid=29&topic=ASP.NET+MVC
http://www.careerride.com/view.aspx?id=111
--Async Controller--
http://msdn.microsoft.com/en-us/library/ee728598%28v=vs.100%29.aspx
1. M - Model
2. V - View
3. C - Controller
What is the ‘page lifecycle’ of an ASP.NET MVC?
Following process are performed by ASP.Net MVC page:
1) App initialization
2) Routing
3) Instantiate and execute controller
4) Locate and invoke controller action
5) Instantiate and render view
What is the Request flow used for ASP.NET MVC framework?
Request flow handles the request from the clients and passes it to the server. The Request flow is as follows:
-Request is being taken from User to controller.
-Controller processes the request from the user and creates a data Model of that particular request.
-Data model that is being created is then passed to View that handles the frontend or the design.
-View then transforms the Data Model by using its own functions in an appropriate output format.
-The output format that is being given by the View is then gets rendered to the Browser and the View will be seen by the user.
What are the ASP.NET MVC folder conventions?
ASP.NET MVC is a framework that focuses on convention over the configuration. The folder structure is very essential for every framework to see:-App_Data: this contains the database files like local instance SQL server express database files.
-Content: it contains the static content that is used for the web application building like CSS, images, etc.
-Controller: it contains the controller classes that are used in ASP.NET MVC architecture.
-Models: it consists of the model classes that are used to interact with the content and go in sync with the MVC architecture of the ASP.NET.
-Scripts: JavaScript files that include the AJAX library and jQuery script files.
-Views: it contains the frontend view that will be seen after the model is rendered.
What is the page lifecycle of an ASP.NET MVC?
The page lifecycle of ASP.NET MVC is having the following process and it is as follows:-App initialization: in this the initiation of the application takes place that allow the application to interact the server and start to run the components.
-Routing: in this the messages are routed to the server for making the delivery of the request easier.
-Instantiate and execute controller: in this way the controller handles the request and passes it on to display the output or replies to the request.
-Locate and invoke controller action: The actions allow the controller to be located correctly and it invokes the correct action that has to be taken on the applications.
-Instantiate and render view: this helps in view the result of the application that is being built.
Can you describe ASP.NET MVC Request Life Cycle?
Following are the steps that are executed in ASP.NET MVC Request Life Cycle.
1. Application first receives the request and looks up Route object in RouteTable collection. Then the RouteData object is created.
2. Then RequestContext instance is created.
3. MvcHandler and pass RequestContext to handler is created.
4. Then IControllerFactory from RequestContext is identified.
5. Then the object of class that implements ControllerBase is created.
6. MyController.Execute method is called.
7. Then ControllerActionInvoker finds the action to invoke on the controller and executes that action on the controller and by calling the model associated view returns.
In which assembly is the MVC framework defined?
System.Web.Mvc
Is it possible to combine ASP.NET webforms and ASP.MVC and develop a single web application?
Yes, it is possible to combine ASP.NET webforms and ASP.MVC and develop a single web application.
What does Model, View and Controller represent in an MVC application?
Model: Model represents the application data domain. In short the applications business logic is contained with in the model.
View: Views represent the user interface, with which the end users interact. In short the all the user interface logic is contained with in the UI.
Controller: Controller is the component that responds to user actions. Based on the user actions, the respective controller, work with the model, and selects a view to render that displays the user interface. The user input logic is contained with in the controller.
What is the greatest advantage of using asp.net mvc over asp.net webforms?
It is difficult to unit test UI with webforms, where views in mvc can be very easily unit tested.
Which approach provides better support for test driven development - ASP.NET MVC or ASP.NET Webforms?
ASP.NET MVC
What are the advantages of ASP.NET MVC?
1. Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested.
2. Complex applications can be easily managed
3. Seperation of concerns. Different aspects of the application can be divided into Model, View and Controller.
4. ASP.NET MVC views are light weight, as they donot use viewstate.
Is it possible to unit test an MVC application without running the controllers in an ASP.NET process?
Yes, all the features in an asp.net MVC application are interface based and hence mocking is much easier. So, we don't have to run the controllers in an ASP.NET process for unit testing.
Is it possible to share a view across multiple controllers?
Yes, put the view into the shared folder. This will automatically make the view available across multiple controllers.
What is the role of a controller in an MVC application?
The controller responds to user interactions, with the application, by selecting the action method to execute and alse selecting the view to render.
Where are the routing rules defined in an asp.net MVC application?
In Application_Start event in Global.asax
Name a few different return types of a controller action method?
The following are just a few return types of a controller action method. In general an action method can return an instance of a any class that derives from ActionResult class.
1. ViewResult
2. JavaScriptResult
3. RedirectResult
4. ContentResult
5. JsonResult
What is the significance of NonActionAttribute?
In general, all public methods of a controller class are treated as action methods. If you want prevent this default behaviour, just decorate the public method with NonActionAttribute.
What is the significance of ASP.NET routing?
ASP.NET MVC uses ASP.NET routing, to map incoming browser requests to controller action methods. ASP.NET Routing makes use of route table. Route table is created when your web application first starts. The route table is present in the Global.asax file.
What are the 3 segments of the default route, that is present in an ASP.NET MVC application?
1st Segment - Controller Name
2nd Segment - Action Method Name
3rd Segment - Parameter that is passed to the action method
Example: http://pragimtech.com/Customer/Details/5
Controller Name = Customer
Action Method Name = Details
Parameter Id = 5
ASP.NET MVC application, makes use of settings at 2 places for routing to work correctly. What are these 2 places?
1. Web.Config File : ASP.NET routing has to be enabled here.
2. Global.asax File : The Route table is created in the application Start event handler, of the Global.asax file.
What is the adavantage of using ASP.NET routing?
In an ASP.NET web application that does not make use of routing, an incoming browser request should map to a physical file. If the file does not exist, we get page not found error.
An ASP.NET web application that does make use of routing, makes use of URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users.
What is the main function of URL routing system in ASP.NET MVC?
-URL routing system provides flexibility to the system and it also enables to define new URL mapping rules that can be used with web applications.-URL routing system is used to map the application and its routing information gets passed to right controller and action method.
-URL routing system processes and executes the method to run the application without using many designed rules.
-It is used to construct the outgoing URLs that can be used to handle the actions that have the ability to map both incoming and outgoing URLs that adds more flexibility to the application code.
-It follows the rules to execute the application globally and handle the logic that is required for the application.
What are the 3 things that are needed to specify a route?
1. URL Pattern - You can include placeholders in a URL pattern so that variable data can be passed to the request handler without requiring a query string.
2. Handler - The handler can be a physical file such as an .aspx file or a controller class.
3. Name for the Route - Name is optional.
Is the following route definition a valid route definition?
{controller}{action}/{id}
No, the above definition is not a valid route definition, because there is no literal value or delimiter between the placeholders. Therefore, routing cannot determine where to separate the value for the controller placeholder from the value for the action placeholder.
What is the use of the following default route?
{resource}.axd/{*pathInfo}
This route definition, prevent requests for the Web resource files such as WebResource.axd or ScriptResource.axd from being passed to a controller.
What is the difference between adding routes, to a webforms application and to an mvc application?
To add routes to a webforms application, we use MapPageRoute() method of the RouteCollection class, where as to add routes to an MVC application we use MapRoute() method.
How do you handle variable number of segments in a route definition?
Use a route with a catch-all parameter. An example is shown below. * is referred to as catch-all parameter.
controller/{action}/{*parametervalues}
What are the 2 ways of adding constraints to a route?
1. Use regular expressions
2. Use an object that implements IRouteConstraint interface
Give 2 examples for scenarios when routing is not applied?
1. A Physical File is Found that Matches the URL Pattern - This default behaviour can be overriden by setting the RouteExistingFiles property of the RouteCollection object to true.
2. Routing Is Explicitly Disabled for a URL Pattern - Use the RouteCollection.Ignore() method to prevent routing from handling certain requests.
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.
If I have multiple filters impleted, what is the order in which these filters get executed?
1. Authorization filters
2. Action filters
3. Response filters
4. Exception filters
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
Give an example for Authorization filters in an asp.net mvc application?
1. RequireHttpsAttribute
2. AuthorizeAttribute
Which filter executes first in an asp.net mvc application?
Authorization filter
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
What filters are executed in the end?
Exception Filters
Is it possible to cancel filter execution?
Yes
What type of filter does OutputCacheAttribute class represents?
Result Filter
What are the 2 popular asp.net mvc view engines?
1. Razor
2. .aspx
What symbol would you use to denote, the start of a code block in razor views?
@
What symbol would you use to denote, the start of a code block in aspx views?
<%= %>
In razor syntax, what is the escape sequence character for @ symbol?
The escape sequence character for @ symbol, is another @ symbol
When I type return View() how does it know which view to return?
-The view that will be returned has the same name as the method in the controller.-For example if you have a method in the Employee controller with the following implementation:
public ActionResult GetEmployees()
{
Return view();
}
-Then we creat a view named GetEmployees in the Employee folder inside of Views. This is not mandatory, however, and we can return give a alternate name to the views passing the name of the view as a string as below:
public ActionResult GetEmployees ()
{
Return view(“EmployeeDetails”);
}
What is an asynchronous controller in ASP.NET MVC?
-AsyncController is a class which is used to create asynchronous action methods which we use for lengthy processes.-By using asynchronous controller we can optimize the performance of web server by avoiding the usage of extra resources once a request is processed.
-The AsyncController class is more useful for the calls of web service which takes long time to process.
How to create an asynchronous controller?
The AsyncController class enables you to write asynchronous action methods. You can use asynchronous action methods for long-running, non-CPU bound requests. This avoids blocking the Web server from performing work while the request is being processed. A typical use for the AsyncController class is long-running Web service calls.
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.
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
What are sections?
Layout pages, can define sections, which can then be overriden by specific views making use of the layout. Defining and overriding sections is optional.
What are the file extensions for razor views?
1. .cshtml - If the programming lanugaue is C#
2. .vbhtml - If the programming lanugaue is VB
How do you specify comments using razor syntax?
Razor syntax makes use of @* to indicate the begining of a comment and *@ to indicate the end. An example is shown below.
@* This is a Comment *@
How to intermix ASP.NET Web Form and MVC?
Adding
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
in the Global.asax file to ignore routes if request contains asp file extension.
Detail info found in the following link:
http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc
MVC Interview questions Link
http://www.dotnetobject.com/Thread-MVC-Interview-Questions-Answers
http://www.wiziq.com/online-tests/32130-asp-net-mvc-interview-questions
http://www.mindstick.com/Interviewer/QuestionPage.aspx?topicid=29&topic=ASP.NET+MVC
http://www.careerride.com/view.aspx?id=111
--Async Controller--
http://msdn.microsoft.com/en-us/library/ee728598%28v=vs.100%29.aspx
No comments:
Post a Comment