Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 11, 2007 08:08 PM by hhariri
Dec 11, 2007 05:59 PM|LINK
Coming from the Delphi world, we had a technology back in 1997 (IIRC) called WebBroker, which still exists today and it consists of pretty much the same thing ASP.NET MVC is now. There were a bunch of WebActions (i.e. Actions) which were called based on
URL and then PageProducers that are similar to RenderView. The same type of processing was done in the view. Obviously there are many improvements in MVC such as automatic parsing of params (which btw I love how params in a method you declare match those passed
in an input field for example, that's very cool), but the idea is pretty much the same.
Point of all this is that in WebBroker we had to events, one called OnBeforeRequest and the other OnAfterRequest (similar I guess to Application_BeginRequest). Any action that were called would first come through this event (if assigned) and you could do
manual routing. With a Handled variable you could indicate whether the processing for that action was done or not. This would easily allow you to control what some people have asked regarding redirecting to login pages, etc. based on authenticated sessions,
and a whole slew of other things.
I've not looked deep enough into the routing to see if I could somehow add a routing to a global controller and then redirect the input to other controllers, but if there isn't, wouldn't you see it as a good idea to have an OnBeforeAction and OnAfterAction
that would allow you to easily to this sort of thing? Again, I'm not too familiar yet with the framework so maybe this is already possible and even more flexible.
Dec 11, 2007 07:23 PM|LINK
Hi, we have three virtual methods that I think accomplish what you're looking for.
OnPreAction, OnPostAction, OnError.
You can override those methods on your controller and return false to stop processing. Returning a boolean is kind of awkward. We plan to have some sort of context or args object so you can set args.Handled = true.
Dec 11, 2007 07:43 PM|LINK
Thanks. But this means I have to override for each controller then? So if I want to redirect users based on authentication I have to do this on each one?
Dec 11, 2007 08:01 PM|LINK
What I did was to create a custom base controller that overrides OnPreAction and then have all my controllers inherit from this. This way there's no need to override OnPreAction in every controller. In
this post Scott mentions that a future version will support pre-action filters (where you could define authentication logic for example) which is probably a better solution.
Dec 11, 2007 08:08 PM|LINK