Is this possible?
I’d like to expose a URL (action) such as http://mysever/myapp/UpdateHeartbeat/.
In my MVC application it looks like
[Authorize]
[AcceptsVerbs(HttpVerbs.Post)]
public ActionResult UpdateHeartbeat()
{
// update date in DB to DateTime.Now
}
Now, in my MVC application the user has logged in via FORMS authentication and they can execute that action to their hearts content.
What I want to do, is hit that URL from a Console application and be able to authenticate (as part of an API that I wouldl like to build) — is there a way I can do that without removing the [Authorize] attribute and adding username/password as parameters to the POST?
The Authorize filter actually gets the IPrincipal for the user from the current context so this would not be possible. You will want an alternate form of auth for that method.
A quick google search provides a link to the following blog post that may be of use:
http://davidhayden.com/blog/dave/archive/2009/04/09/CustomAuthorizationASPNETMVCFrameworkAuthorizeAttribute.aspx