How to setup 2 actions with the same name, 1 Authorized and 1 not Authorized?

Is it possble to have something like this in ASP.NET MVC...

[Authorize]
[AcceptVerbs(HttpVerbs.Get)]
public string AddData(string Issues, string LabelGUID)
{
    return "Authorized";
}

[AcceptVerbs(HttpVerbs.Get)]
public string AddData()
{
    return "Not Authorized";
}

So if the user is not logged in, it defaults to the un-Authorized action.

Answers


Yes, its possible. You would need to create your own ControllerActionInvoker and override the FindActionMethod member. I'd let the base class do it's work and then check to see if the method it returns satisfies your criteria and if not, return a better match.

I'm doing something like this to allow my Controllers to have a "Default Action" and it works well. Check out MvcContrib and their implementation of their ActionInvoker for a really nice example.


Need Your Help

Fetching related parent objects in a chain in Django

django foreign-keys models relation

As always, please forgive my ignorance. I promise I searched first.

Unable to add overlay to MPMoviePlayerController in SDK 4.1

iphone

This is a follow-on from: Overlay on top of Streaming MPMoviePlayerController

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.