Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 639679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:52:10+00:00 2026-05-13T20:52:10+00:00

First of all, it needs to create some codes that handle any error in

  • 0

First of all, it needs to create some codes that handle any error in my application like the following code.

public class HandleSomeErrorAttribute : HandleErrorAttribute
{
    public string ControllerName { get; set; }
    public string ActionName { get; set; }

    public override void OnException(ExceptionContext filterContext)
    {
        base.OnException(filterContext);

        if(filterContext.Result != null)
        {
            var viewResult = filterContext.Result as ViewResult;

            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(
                 new
                 {
                     controller = ControllerName,
                     action = ActionName,
                     errorInfo = "test"
                 }
            ));
        }
    }
}

Everything works fine if I send test as errorInfo value. In the other hand, if I send some errorInfo object as errorInfo value, action controller will not receive any errorInfo value. It always is null.

I know this behavior is designed to handle any values in form collection that is sent by web browser when user submits form. So, it always read only string value and parses it to object.

So, is it possible to do that?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:52:10+00:00Added an answer on May 13, 2026 at 8:52 pm

    After I search some related question in Stackoverflow, I just realize that any redirect action in ASP.NET sends HTTP 302 code to browser. After that, browser will create new request to fetch new URL (that can be found in HTTP 302 header).

    Therefore, it is impossible to directly send any complex objects (without serialize it) to browser and order browser to send it back to server. Although, it is possible, but I think it is so silly to do that. Because you can use the following code to call another action without send HTTP 302 to browser.

    public class TransferResult : ActionResult
    {
        public TransferResult(string controllerName, string actionName, RouteValueDictionary routeValues = null)
        {
            RouteValues = routeValues ?? new RouteValueDictionary();
    
            if (!string.IsNullOrEmpty(controllerName))
            {
                RouteValues[MvcApplication.ControllerRouteKey] = controllerName;
            }
    
            if (!string.IsNullOrEmpty(actionName))
            {
                RouteValues[MvcApplication.ActionRouteKey] = actionName;
            }
    
            if(RouteValues[MvcApplication.ControllerRouteKey] == null)
            {
                throw new ArgumentException(Resources.ControllerNameIsNotFoundInRouteValueDictionary, "controllerName");
            }
    
            if (RouteValues[MvcApplication.ActionRouteKey] == null)
            {
                throw new ArgumentException(Resources.ActionNameIsNotFoundInRouteValueDictionary, "actionName");
            }
        }
    
        public TransferResult(RouteValueDictionary routeValues)
            : this(null, null, routeValues)
        {
        }
    
        public RouteValueDictionary RouteValues { get; set; }
    
        public override void ExecuteResult(ControllerContext context)
        {
            var routeData = new RouteData();
    
            foreach (var item in RouteValues)
            {
                routeData.Values.Add(item.Key, item.Value);   
            }
    
            var contextWrapper = new HttpContextWrapper(HttpContext.Current);
            var request = new RequestContext(contextWrapper, routeData);
    
            var controller = ControllerBuilder.Current.GetControllerFactory().CreateController(context.RequestContext, RouteValues[MvcApplication.ControllerRouteKey].ToString());
            controller.Execute(request); 
        }
    } 
    

    Next, I create some handle error for handling some error type and transfering it to another action controller.

    public class SomeHandleErrorAttribute : HandleErrorAttribute
    {
        public SomeHandleErrorAttribute (string controllerName, string actionName)
        {
            ExceptionType = typeof (EntityException);
            ControllerName = controllerName;
            ActionName = actionName;
        }
    
        public string ControllerName { get; set; }
        public string ActionName { get; set; }
    
        public override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);
    
            if(filterContext.Result != null)
            {
                var routeValue = new RouteValueDictionary
                 {
                     {"errorInfo", filterContext}
                 };
    
                filterContext.Result = new TransferResult(ControllerName, ActionName, routeValue);
            }
        }
    }
    

    Finally, I create the action for handling this error.

    public class ErrorController : Controller
    {
        public string EntityError(ExceptionContext errorInfo)
        {
            return string.Format("Handle error for {0} ", errorInfo.Exception.Message);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I know how to build a Java application. But I have
I've been tasked with creating some sort of service that will take any e-mail
I have some Java code that validates XML against an XSD. I am using
I have a very old application that now needs to be friendly to Windows
First of all, I don't need a textual comparison so Beyond Compare doesn't do
i need to redirect all of the stdout of a program except the first
First of all, I'm fairly sure snapping to grid is fairly easy, however I've
First of all: I am not an experienced ClearCase user, but I have lots
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First of all there is a partial question regarding this, but it is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.