Solved

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

Posted on 2011-02-14
2
664 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 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