Asp.net mvc 4 获取HandleError属性中的服务器文件夹路径和Request.IsAjaxRequest()

Asp.net mvc 4 获取HandleError属性中的服务器文件夹路径和Request.IsAjaxRequest(),asp.net-mvc-4,exception-handling,Asp.net Mvc 4,Exception Handling,我正在尝试在ASP.NETMVC4应用程序中扩展HandleErrorAttribute。但问题是我无法获取~/App_数据的路径。另一个问题是我想定义它是否是AjaxRequest。我的代码如下- using sCommonLib; using System; using System.Web; using System.Web.Mvc; using sCommonLib; public class HandleErrors:System.Web.Mvc.HandleErrorAttribu

我正在尝试在ASP.NETMVC4应用程序中扩展HandleErrorAttribute。但问题是我无法获取~/App_数据的路径。另一个问题是我想定义它是否是AjaxRequest。我的代码如下-

using sCommonLib;
using System;
using System.Web;
using System.Web.Mvc;
using sCommonLib;

public class HandleErrors:System.Web.Mvc.HandleErrorAttribute
{
    public override void OnException(System.Web.Mvc.ExceptionContext filterContext)
    {       
        if (filterContext.ExceptionHandled)
        {
            return;
        }
        else
        {
            var path = HttpContext.Server.MapPath("~/App_Data"); //need help here              
            string actionName = filterContext.RouteData.Values["action"].ToString();
            Type controllerType = filterContext.Controller.GetType();
            var method = controllerType.GetMethod(actionName);
            var returnType = method.ReturnType;

            if (returnType.Equals(typeof(JsonResult)))
            {
                filterContext.Result = new JsonResult()
                {
                    Data = "Some error."
                };
            }

            if (returnType.Equals(typeof(ActionResult))
            || (returnType).IsSubclassOf(typeof(ActionResult)))
            {
                filterContext.Result = new ViewResult
                {
                    ViewName = "URL to the errror page"
                };
            }
        }

        filterContext.ExceptionHandled = true;
    }
}
有线索吗

试试这个

if(Request.IsAjaxRequest())
{
    var path = HSystem.Web.HttpContext.Current.Server.MapPath(@"~/App_Data"); // here              
    string actionName = filterContext.RouteData.Values["action"].ToString();
    Type controllerType = filterContext.Controller.GetType();
    var method = controllerType.GetMethod(actionName);
    var returnType = method.ReturnType;

    if (returnType.Equals(typeof(JsonResult)))
    {
        filterContext.Result = new JsonResult()
        {
            Data = "Some error."
        };
    }

    if (returnType.Equals(typeof(ActionResult)) || (returnType).IsSubclassOf(typeof(ActionResult)))
    {
        filterContext.Result = new ViewResult
            {
                ViewName = "URL to the errror page"
            };
    }
}

希望有帮助:)

这是问题的一部分。那么ajaxRequest呢?