在MVC5中使用异常过滤器

时间:2016-01-26 17:06:22

标签: asp.net asp.net-mvc visual-studio-2013 asp.net-mvc-5.2

我花了很多时间但是我遇到了这个错误。当我在MVC5 Web应用程序中添加异常过滤器时。

我的代码如下所示。

HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AutomatedTellerMachine.Controllers
{
    public class HomeController : Controller
    {   
        [MyLoggingFilter]
        public ActionResult Index()
        {
            throw new StackOverflowException();
            return View();
        }
        [ActionName("about-this-atm")]
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View("About");
        }


        public ActionResult Contact()
        {
            ViewBag.TheMessage = "Having trouble? Send us a message.";

            return View();
        }
        [HttpPost]
        public ActionResult Contact(string message)
        {
            ViewBag.TheMessage = "Thanks, we get your meaasge.";

            return View();
        }

        public ActionResult Foo()
        {
            return View("About");
        }
        public ActionResult Serial(string letterCase)
        {
            var serial = "ASPNETMVC5ATM1";
            if (letterCase == "lower")
            {
                return Content(serial.ToLower());
            }
            return Content(serial);
        }
    }
}

FilterConfig.cs

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

namespace AutomatedTellerMachine
{
    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
            filters.Add(new MyLoggingFilterAttribute());
        }
    }
}

相关配置:

<system.web>
  <authentication mode="None"/>
  <compilation debug="true" targetFramework="4.5"/>
  <httpRuntime targetFramework="4.5"/>
  <customErrors mode="On"/>
</system.web>

但没有什么是重定向的,出了点问题。

0 个答案:

没有答案