I’m playing with ASP.NET Web API and I have the following:
public Guid GetLogon(string username, string password)
{
return new X.Authentication().Logon(username, password);
}
public void PostLogoff(Guid sessionId)
{
new X.Authentication().Logoff(sessionId);
}
This is being called from the client side as follows:
$(document).ready(function () {
logon("MyUsername", "MyPassword", function (guid) {
$("#sessionId").html(guid);
logoff($("#sessionId").html(), function () {
//Logged out action here
});
});
});
This all works, but I don’t like to have to prefix the Action names with the http verb, like GetLogon or PostLogoff. Is there a way to make them just Logon and Logoff?
I tried the following, which didn’t work:
[System.Web.Mvc.AcceptVerbs(HttpVerbs.Get)]
public Guid Logon(string username, string password)
{
return new X.Authentication().Logon(username, password);
}
[System.Web.Mvc.AcceptVerbs(HttpVerbs.Post)]
public void Logoff(Guid sessionId)
{
new X.Authentication().Logoff(sessionId);
}
Thank you in advance
Not sure if this is the cause, but in my APIController the AcceptVerbs attribute is in a different namespace:
The
[HttpGet]and[HttpPost]attribute are in the same namespaceI have a number of regular MVC controllers in the same project; they use the namespace you have described above, but not the API Controllers
Try this: