Solved

Using MVC3 how do I get control before the Controller Action?

Posted on 2011-02-14
2
668 Views
Last Modified: 2012-05-11
We installed MVC3 last week and have already changed a few views to use Razor, with .cshtml extensions. But we upgraded to MVC3 so we'd have the power to access the code before the first line of code is hit in the Controller Actions.

How do I do this?

And what kinds of things can be done with this new technology?

I have written a custom object that inherits from AuthorizeAttribute, and overrides AuthorizeCore(HttpContextBase httpContext).  Would I still use this kind of authentication as an annotation above the Controller Actions?

Thanks,
newbieweb
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 500 total points
ID: 34894320
Just as an FYI, you didn't need to upgrade to MVC3 to do what you want to do, you could have done it with MVC2.

Create a method on your controller called OnActionExecuting. This method will override the base class method of the same name. It runs before your action method and you can do whatever you want in it.

The rest of your question is rather vague. I always recommend that someone new to MVC go through the free tutorials and training available at http://www.asp.net/mvc.
0
 

Author Closing Comment

by:newbieweb
ID: 34916346
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question