Posted by: Cirilo Meggiolaro | 05/4/2009

Tip of the day #202 – ASP.NET MVC – Hiding public methods with NonAction attribute

Any method in a controller class defined as public is by default an action method accessible via url.

If you need a public method in a controller class but you don’t want to expose it you can “hide” it by decorating the method with the NonAction attribute. It makes the method unavailable if requested via browser and a 404 error will be retrieved if you try to access it.

How to…

Implement is pretty straightforward.

[NonAction]
public void MyPublicMethod() { }


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: