Up to date ASP.Net MVC 3 Request-Handling Pipeline Diagram? - asp.net-mvc

Can anyone point me to an up-to date diagram of the ASP.Net MVC 3 request handling pipeline?
I've got an older version (MVC v1, v2), but it's no longer accurate, given the introduction of IControllerActivator in MVC3 (and possibly other framework changes).

This is somewhat late for an answer but this could help someone (definitely helped me)
ASP.NET MVC Pipeline
Taken from this great article: An Introduction to ASP.NET MVC Extensibility

This is a Request-handling Pipeline for ASP.NET MVC 2: http://ajaxus.net/wp-content/uploads/2010/01/asp_net_mvc_poster.pdf (or see page 228, Pro ASP.NET MVC 2 by Steven Sanderson).
The request pipeline is (maybe) not change in V3, but MVC 3 is extend some point to allow injection in every node of pipeline.
Example:
- At node: Controller factory:
+ ControllerBuilder create an instance of IControllerFactory (ex: the default factory)
+ factory implement Create() of IControllerFactory by:
++ Using an instance of IControllerActivation (activation)
++ Call activation.Create() of IControllerActivation to get instance of controller
So, IControllerActivation is work in DefaultControllerFactory. We can still use DefaultControllerFactory and replace IControllerActivation, or replace the DefaultControllerFactory with custom IControllerFactory (with or without use IControllerActivation)

Related

what is namespace for Compare attribute MVC 4?

i need to write a registration form and need to [Compare] attribute for my Confirm Password field.
i'm using MVC 4 .
Is there this attribute in mvc 4?
if answer is yes what namespace need to use?
As of MVC4, the [Compare] attribute is potentially in two different namespaces:
System.Web.Mvc
System.ComponentModel.DataAnnotations (with Framework 4.5).
The Mvc version is IClientValidatable and all the benefits that brings - front end validation etc..
With Asp.NET Mvc 5 the System.Web.Mvc one is marked as obsolete, which may be something to bear in mind if you are going to be migrating upwards soon.
If your model mixes the two namespaces above, you can expicitly choose which one to use my using the full namespace - e.g. [System.Web.Mvc.Compare( .. )]

asp.net mvc 4 - Who calls _ViewStart.cshtml and what is the sequence of steps

I am new to MVC so please bear with me. I am trying to find out who calls Viewstart.cshtml and what is the sequence of steps involved there? is it called after the route table is accessed or before it?
The RazorViewEngine has an internal readonly field "ViewStartFileName" which specifies the name of the start view. _ViewStart.cshtml (or .vbhtml) is called each time a RazorView instance is rendered (specifically when the RenderView() method is being executed).
So the "who" would be the RazorViewEngine with its corresponding RazorView class (including their base classes). To get a quite good overview on the MVC request pipeline I recommend this pdf.
Check the image below... (What is the 'page lifecycle' of an ASP.NET MVC page, compared to ASP.NET WebForms?)

ASP.NET MVC 3 Preview configure for ninject

I'm giving ASP.NET MVC 3 Preview 1 a spin and want to configure ninject with it. Is the best way still to use ninject.web.mvc extension? The sample Scott Gu posts doesn't run. It throws an "Error activating IControllerFactory" exception.
You don't need "Ninject.Web.Mvc" to configure Ninject in MVC 3, as I've blogged in a post titled "Dependency Injection in ASP.NET MVC 3 using Ninject".
I believe Scott Gu's code should read...
public static void RegisterServices(IKernel kernel)
{
kernel.Bind<IProductRepository>().To<SqlProductRepository>();
kernel.Bind<IControllerFactory>().To<NinjectControllerFactory>();
}
Where the NinjectControllerFactory is found in...
using Ninject.Web.Mvc;
So yes, you do still need the mvc extension for Ninject.
Perhaps there is a better/newer way to define the default controller factory in MVC 3, but that is how I did it.
There may also be some strange behavior coming from MvcServiceLocator as indicated in this post.
Make sure that when you're calling using the ninject kernel from your IDependencyResolver, that you're calling
_kernel.TryGet(serviceType)
The MVC framework will try to grab a different IControllerFactory if it is available, if you call "TryGet", it will return null and the framework will use the default Controller Factory instead.
If you're using unity instead, make sure you wrap the resolve in a try/catch block and return null in the catch. Although that will be kind of slow, because you don't really want to have a catch block be treated as a normal part of execution flow.

Is there a way to rename the RequestVerificationToken cookie name?

Using ASP.net MVC v2.0, Any way to change the name of the __RequestVerificationToken cookie? In an effort to conceal our underlying technology stack, I’d like to rename the cookie to something that can’t be traced back to ASP.Net MVC.
More info on this at Steve Sanderson's blog.
ASP.NET MVC 3 and 4 let you change the cookie name by setting the static AntiForgeryConfig.CookieName property.
(Msdn reference here)
I know that the question asks specifically about ASP.NET MVC 2, but this question still returns high up the search engine rankings for appropriate queries such as "ASP.NET MVC AntiForgeryToken cookie name". I thought I'd add the information here to save others from decompiling the ASP.NET MVC 3+ source code like I did.
Looking at the MVC 2 source code I dont think it's possible to change the cookie name. The AntiForgeryData class starts:
private const string AntiForgeryTokenFieldName = "__RequestVerificationToken";
and to get the cookie name it just calls:
string cookieName = AntiForgeryData.GetAntiForgeryTokenName(ViewContext.HttpContext.Request.ApplicationPath);
in the HtmlHelper class. It takes the application path and converts it to base 64 and appends it onto the end of __RequestVerificationToken which is what you see when you view the source.
If you really need to change the name I'd recommend downloading the MVC 2 source code from codeplex and look at creating your own html helper and anti forgery token using the source code as a reference. But in doing this you could always introduce your own bugs...

Tweaking asp.net mvc

I really love the "one model in - one model out" idea of Fubu MVC. A controller would look something like this
public class MyController
{
public OutputModel MyAction(InputModel inputModel)
{
//..
}
}
and the service locator would automagically fill in all the required dependencies in the constructor.
This makes the controller very easy to test.
So my question is: How would you go about tweaking asp.net mvc to allow this simplicity in the controllers ?
What you're looking for the is the ControllerActionInvoker. You'll have to implement your own and override/take over handling a lot of the pipeline work that ASP.NET MVC.
For reference, check out Jonathon Carter's 2-part post on doing ControllerActionInvokers:
http://lostintangent.com/2008/07/03/aspnet-mvc-controlleractioninvoker-part-1/
and
http://lostintangent.com/2008/07/07/aspnet-mvc-controlleractioninvoker-part-2/
Also, the Oxite team did this in the 2nd release of Oxite, you can check out their source here:
http://oxite.codeplex.com/SourceControl/changeset/view/30544
Here's a link directly to their ControllerActionInvoker implementation:
http://oxite.codeplex.com/SourceControl/changeset/view/30544#442766
Never really dug deep inside ASP.NET MVC internals, but I guess custom ModelBinder and ActionResult will do the job.

Resources