I have multiple actions methods in a Controller that share the same ActionName, like this:
[ActionName("Example")]
[DefinedParameter(Name = "xID")]
[HttpPost()]
public ActionResult ExampleX(Guid xID)
{
....
}
[ActionName("Example")]
[DefinedParameter(Name = "yID")]
[HttpPost()]
public ActionResult ExampleY(Guid yID)
{
....
}
In addition to this I use a action selector via the DefinedParameter attribute, like this:
public class DefinedParameterAttribute : ActionMethodSelectorAttribute
{
public string Name { get; set; }
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
HttpRequestBase request = controllerContext.RequestContext.HttpContext.Request;
return request[this.Name] != null;
}
}
In most cases this works perfectly.
In some cases however I get the following error:
"AmbiguousMatchException Exception message: The current request for action 'Example' on controller type 'ExampleController' is ambiguous between the following action methods: ...."
I get this error when:
I submit a request (that takes some time) with example parameter xID.
While the request from step 1 is still processing on the server (no response returned yet), I submit a second request (example parameter yID).
I discovered that in those cases the request indeed contains both parameters; in my example xID and yID. That explains the error.
So it seems that the server somehow reuses the same request and adds the parameter from the second submit.
NB: Please know that I mostly use action methods with a unique name. That's the best way to go. But in some cases the described example can be a better approach.
How can I solve and/or avoid this error?