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 8774911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:41:01+00:00 2026-06-13T18:41:01+00:00

I have an MVC action which generates a Word document: [HttpGet] public ActionResult ExportToWord(string

  • 0

I have an MVC action which generates a Word document:

    [HttpGet]
    public ActionResult ExportToWord(string docId)
    {
    try
    {
      //...
      //Word-document generating is done here...
      //...
      return File(stream, MIMEAssistant.GetMIMEType("docx"), fileName + ".docx");
    }
    catch (Exception e)
    {
        throw new Exception("Problem with generating! " + e.ToString());
    }

If I have so I get en Asp.Net standard exception with URL

http://localhost:18314/Export/ExportToWord?docId=5

If I have so I have the same URL. Redirection is not done. It must go to

http://localhost:18314/Home/ErrorPage.

Now users do not get any error page, just reloading of the page. The page is reloaded not correctly because the URL is

http://localhost:18314/Export/ExportToWord?docId=5

I hope it was understandable description 🙂

Question: How to make correct redirection to …/Home/ErrorPage and send an exception by using Elmah logging facility?

  • 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-13T18:41:02+00:00Added an answer on June 13, 2026 at 6:41 pm

    You can return RedirectToAction("ErrorPage", "Home"); instead of throwing exception. There are RedirectToAction overloads which allows to pass route values (so you can pass your error id, exception type etc).

    UPDATE

    As you want to log exceptions using ELMAH, then I suggest logging errors manually and redirecting to action with:

    catch(Exception e)
    {
        Elmah.ErrorSignal.FromCurrentContext().Raise(e);
        return RedirectToAction("ErrorPage", "Home");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have an Action like this: public ActionResult DoStuff(List<string> stuff) { ... ViewData[stuff]
I have a JavaScript function which redirect to Asp.net MVC action method. [AcceptVerbs(HttpVerbs.Post)] public
On ASP.NET MVC 3, assume that we have following controller action: public ActionResult Index()
I have a jquery routine that calls an MVC action which will do a
I have an ASP.NET MVC 3 application which has a post action called Create
I have an ASP.NET MVC 3 action method which accepts a HttpFileCollectionBase in the
I have ASP.NET MVC application with action which should process posted XML data. At
I'm using MVC and i have a controller action which handles several different view
In my asp mvc 3 application, I have an action which allows the user
I have an ASP.NET MVC web site. I have many actions which require authentication

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.