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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:03:38+00:00 2026-06-09T21:03:38+00:00

I am having a problem with 500 error handling, working in VB.NET. My problem

  • 0

I am having a problem with 500 error handling, working in VB.NET.

My problem is that when a 500 error is thrown, my site redirects to my error page. But if I inspect the Network tab in Chrome, I see that I get a 200 (OK) for the page that threw the error and then another 200 for the page that was redirected to.

Am I right in thinking that a 500 error should be returned on the page that throws the error, and a 200 returned for the redirected page?

My web config’s error handling is set up as follows:

<customErrors defaultRedirect="~/error.aspx" mode="On">
      <error statusCode="400" redirect="~/400Error.aspx" />
      <error statusCode="500" redirect="~/error.aspx?code=500" />
    </customErrors>

<httpErrors errorMode="Custom" existingResponse="Replace">
      <clear />
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/error.aspx" responseMode="ExecuteURL" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="500" prefixLanguageFilePath="" path="/error.aspx?code=500" responseMode="ExecuteURL" />
      <remove statusCode="400" subStatusCode="-1" />
      <error statusCode="400" prefixLanguageFilePath="" path="/400Error.aspx" responseMode="ExecuteURL" />
    </httpErrors>

But this alone results in the problem I describe above.

I thought that maybe I could return a 500 on the page by using either Application_Error in the Global.asax file:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Response.StatusCode = System.Net.HttpStatusCode.InternalServerError
        Server.ClearError()
        Server.Transfer("error.aspx?code=500")
    End Sub

Or on the page level by adding similar code in my Master Page:

 Protected Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
        Response.StatusCode = System.Net.HttpStatusCode.InternalServerError
        Server.ClearError()
        Server.Transfer("error.aspx?code=500")
    End Sub

By catching the error on the page level I am redirected to the error page with the same results as produced by handling the error in the web.config file. Whereas catching the error on the Application level seems to return the error page without doing a redirect(?), and just a single 200 is returned in this instance.

I have tried a combination of the code above – I understand that the Server.ClearError() will stop the error from ‘bubbling up’ to the web.config level? But I have tried with and without that line without much success.

Could anyone tell me if it would be correct to return the 500 on the page that throws the error and if so, what I can do to achieve this?

  • 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-09T21:03:40+00:00Added an answer on June 9, 2026 at 9:03 pm

    I found that if I throw an exception at the application level, then I achieve the result of returning the error page without redirecting, as well as returning the 500 Error:

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            Dim ex = Server.GetLastError()
            //log error details
            Response.StatusCode = System.Net.HttpStatusCode.InternalServerError
            Server.ClearError()
            Throw New Exception
        End Sub
    

    I am not sure if this is the best way of solving my problem but will leave up in case anyone else finds this useful.

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

Sidebar

Related Questions

Probably this is another user error, but I'm having a weird problem with this.
I'm having a problem completely properly configuring behavior for 500 Internal Server Error pages.
I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
I'm working with java images for the first time and having a problem viewing
I'm having an odd problem: I have this code that I'm using exactly as-is
I using a reCaptcha on my web page under asp.net mvc. This web site
I am having this error on my page. iisnode encountered an error when processing
I have a page in a project I'm working on where I'm having a
I am having a problem with errors such as: HTTP Status 500 - --------------------------------------------------------------------------------
I am having a website (developed in ASP.NET 2.0 (C#)) registered with godaddy.com But

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.