How to add custom hooks to controllers in ASP.NET MVC2

Posted by Adrian on Stack Overflow See other posts from Stack Overflow or by Adrian
Published on 2010-05-28T10:09:43Z Indexed on 2010/05/28 10:11 UTC
Read the original article Hit count: 300

Filed under:
|
|
|

Hi,

I've just started a new project in ASP.net 4.0 with MVC 2.

What I need to be able to do is have a custom hook at the start and end of each action of the controller.

e.g.

public void Index() {  
    *** call to the start custom hook to externalfile.cs (is empty so does nothing)

    ViewData["welcomeMessage"] = "Hello World";

    *** call to the end custom hook to externalfile.cs (changes "Hello World!" to "Hi World")

    return View();
}

The View then see welcomeMessage as "Hi World" after being changed in the custom hook.

The custom hook would need to be in an external file and not change the "core" compiled code. This causes a problem as with my limited knowledge ASP.net MVC has to be compiled.

Does anyone have any advice on how this can be achieved?

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc