2

I have a multi-page form in my application, and as such, each method posts to the next. This works fine unless you try to visit the URL of one the methods decorated with [HttpPost].

Is there any way I can route all 404 requests within this specific controller to the Index method?

ediblecode
  • 10,724
  • 16
  • 62
  • 111
  • have a look on MVC routing catchall {*url}, you might check this article http://richarddingwall.name/2008/08/09/three-common-aspnet-mvc-url-routing-issues/ – Monah Jul 23 '15 at 07:10

1 Answers1

1

I will post this as an answer because I am not able to add it as comment

have a look to this link, it might help you

The idea you can catch the error in the OnActionExecuting and there you can make redirect

also as mentioned in this page in the answer, you can handle the Controller.OnException

public class BaseController: Controller
{
    protected override void OnException(ExceptionContext filterContext)
    {
        // Bail if we can't do anything; app will crash.
        if (filterContext == null)
            return;
            // since we're handling this, log to elmah

        var ex = filterContext.Exception ?? new Exception("No further information exists.");
        LogException(ex);

        filterContext.ExceptionHandled = true;
        var data = new ErrorPresentation
            {
                ErrorMessage = HttpUtility.HtmlEncode(ex.Message),
                TheException = ex,
                ShowMessage = !(filterContext.Exception == null),
                ShowLink = false
            };
        filterContext.Result = View("Index", data); // to redirect to the index page
    }
}

after this you can let all your controller to inhert from BaseController

Community
  • 1
  • 1
user5135401
  • 218
  • 1
  • 9