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

  • SEARCH
  • Home
  • 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 7918285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:27:04+00:00 2026-06-03T15:27:04+00:00

I have custom errors turned on in webconfig and redirecting to /Error/Trouble. This is

  • 0

I have custom errors turned on in webconfig and redirecting to “/Error/Trouble”. This is working as designed. Elmah is logging the error. The error view is being displayed too.

The problem is I want to inspect the thrown error in the Trouble action of my Error controller. When an error is thrown, how do you get access to it after MVC has redirected you to the custom error handler?

I’m throwing an exception if CurrentUser is null:

        if (CurrentUser == null)
        {
            var message = String.Format("{0} is not known.  Please contact your administrator.", context.HttpContext.User.Identity.Name);
            throw new Exception(message, new Exception("Inner Exception"));
        }

I want to be able to access this in my custom error handler (“Error/Trouble”). How do you access the exception?

Here’s my trouble action:

    public ActionResult Trouble()
    {
        return View("Error");
    }

Here’s my view:

@model System.Web.Mvc.HandleErrorInfo

<h2>
    Sorry, an error occurred while processing your request.
</h2>
@if (Model != null)
{
    <p>@Model.Exception.Message</p>
    <p>@Model.Exception.GetType().Name<br />
    thrown in @Model.ControllerName @Model.ActionName</p>
    <p>Error Details:</p>
    <p>@Model.Exception.Message</p>
}

System.Web.Mvc.HandleErrorInfo is the model for my Trouble view and it’s empty. Thanks for your help.

  • 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-06-03T15:27:06+00:00Added an answer on June 3, 2026 at 3:27 pm

    I found a workaround:

    in Global.asax I do this:

            protected void Application_Error()
        {
            var exception = Server.GetLastError();
    
            HttpContext.Current.Application.Lock();
            HttpContext.Current.Application["TheException"] = exception;
            HttpContext.Current.Application.UnLock();
        }
    

    In Error/Trouble I do this:

            var caughtException = (Exception)HttpContext.Application["TheException"];
            var message = (caughtException!= null) ? caughtException.Message : "Ooops, something unexpected happened.  Please contact your system administrator";
            var ex = new Exception(message);
            var errorInfo = new HandleErrorInfo(ex, "Application", "Trouble");
            return View("Error", errorInfo);
    

    This is working. But it seems like a weird way to go about it. Does anyone have a better solution? Thanks for your help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a web application that has custom errors turned on so that users
I have a custom error handler attached to E_ALL PHP errors. In an external
I have created a custom function and I am getting this error. I dont
I have encountered this error when trying to delete a cell, using a custom
I have implemented custom errors in my asp.net mvc application by following this article
I have custom errors turned on and when I go to www.mywebsite.com/video/default.aspx it shows
I have a asp.net mvc application and am trying to get custom errors working
I have a custom error page set up for my application: <customErrors mode=On defaultRedirect=~/errors/GeneralError.aspx
I have a custom error page that should display for HTTP 404 errors. It
When I have my custom errors disabled, Elmah is taking all exceptions that occur

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.