在asp.net mvc 4中,我编写了一个自定义的异常处理程序,作为名为HandleCustomError的属性.
在这个处理程序中,我应该知道当前请求的动作,然后我就可以知道这个动作的返回类型是什么.我将返回"return type view()和json"的不同数据.
但是,现在我有两个同名的动作,但一个是"Get",另一个是"Post".方法"GetMethod"返回错误:"System.Reflection.AmbiguousMatchException"
public class HandleCustomError : System.Web.Mvc.HandleErrorAttribute
{
public override void OnException(System.Web.Mvc.ExceptionContext filterContext)
{
//base.OnException(filterContext);
if (filterContext.ExceptionHandled)
{
return;
}
else
{
//Determine the return type of the action
string actionName = filterContext.RouteData.Values["action"].ToString();
Type controllerType = filterContext.Controller.GetType();
var method = controllerType.GetMethod(actionName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
var returnType = method.ReturnType;
}
....(Omitted)
Run Code Online (Sandbox Code Playgroud)