Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-14
2
Medium Priority
?
671 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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