Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now