0

I have spend lot of time but I am stuck in this error. When I am adding Exception Filter in MVC5 Web Application.

My code is shown as following.

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());
        }
    }
}

Relevant configuration:

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

But nothing is redirecting, something is gone wrong.

mason
  • 31,774
  • 10
  • 77
  • 121
nabia saroosh
  • 399
  • 1
  • 14
  • 36
  • What is your customErrors setting in web.config? https://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute(v=vs.118).aspx – Steve Greene Jan 26 '16 at 17:23
  • You have a lot of extra code in your post. Please pay attention to the *minimal* in [MCVE](http://stackoverflow.com/help/mcve). – mason Jan 26 '16 at 17:25
  • My customErrors setting in web.config is – nabia saroosh Jan 26 '16 at 17:25
  • can you show what type(s) `MyLoggingFilterAttribute` inherits from? – Glenn Ferrie Jan 26 '16 at 17:35
  • Also what happens when you try to navigate to the `Home/Index` route? – Glenn Ferrie Jan 26 '16 at 17:37
  • Add a redirect to your custom handler: http://stackoverflow.com/questions/13905164/how-to-make-custom-error-pages-work-in-asp-net-mvc-4 – Steve Greene Jan 26 '16 at 17:37
  • Yes, @GlennFerrie this problem is about exception filter. – nabia saroosh Jan 26 '16 at 17:46
  • Please post the code for `MyLoggingFilterAttribute`. Without it, there is no way for us to reproduce (or spot) your issue. – NightOwl888 Jan 26 '16 at 18:20
  • @NightOwl888 - He's not having problems with the Logging filter. – Steve Greene Jan 26 '16 at 18:32
  • @SteveGreene, I hope you have understand my problem. I am just adding exception filter in this project. I have done add this exception in it but how I can handle it. It's a problem. Please tell me code how can I handle it. – nabia saroosh Jan 26 '16 at 18:47
  • What are you getting when you throw an exception? Do you have an error.cshtml view in your shared view folder? http://www.prideparrot.com/blog/archive/2012/5/exception_handling_in_asp_net_mvc#handleerror – Steve Greene Jan 26 '16 at 19:46
  • Yes @SteveGreene it is showing me an error when I run my application. The error is "System.StackOverflowException' occurred in AutomatedTellerMachine.dll but was not handled in user code" – nabia saroosh Jan 27 '16 at 06:57

0 Answers0