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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:41:24+00:00 2026-06-11T13:41:24+00:00

With the following configuration in my web.config file, <customErrors mode=On redirectMode=ResponseRedirect > <error statusCode=404

  • 0

With the following configuration in my web.config file,

<customErrors mode="On" redirectMode="ResponseRedirect" >
    <error statusCode="404" redirect="/404" />
</customErrors>   
<httpErrors errorMode="Custom">
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="/404" responseMode="ExecuteURL" />
</httpErrors>

The 404 page works nice, but for urls that end with .aspx an redirect happens and the query string for the url is removed. If I change parameter “redirectMode” in the tag “customErrors” to “ResponseRewrite” it stops working for .aspx urls and I just get the default ASP.NET error page. How can I fix this? I need the query string on the 404 page to be able to redirect the user to the correct new url.

/Viktor

  • 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-11T13:41:25+00:00Added an answer on June 11, 2026 at 1:41 pm

    Ok, ended up writing my own http module for this,

        public class FileNotFoundModule : IHttpModule
    {
        private static CustomErrorsSection _configurationSection = null;
        private const string RedirectUrlFormat = "{0}?404;{1}";
    
        public void Dispose()
        {
        }
    
        public void Init(HttpApplication context)
        {
            context.Error += new EventHandler(FileNotFound_Error);
        }
    
        private void FileNotFound_Error(object sender, EventArgs e)
        {
            var context = HttpContext.Current;
            if (context != null && context.Error != null)
            {
                var error = context.Error.GetBaseException() as HttpException;
                if (error != null && error.GetHttpCode() == 404 &&
                    (ConfigurationSecion.Mode == CustomErrorsMode.On || (!context.Request.IsLocal && ConfigurationSecion.Mode == CustomErrorsMode.RemoteOnly)) &&
                    !string.IsNullOrEmpty(RedirectUrl) && !IsRedirectLoop)
                {
                    context.ClearError();
                    context.Server.TransferRequest(string.Format(FileNotFoundModule.RedirectUrlFormat, RedirectUrl, context.Request.Url));
                }
            }
        }
    
        private bool IsRedirectLoop
        {
            get
            {
                var checkUrl = string.Format(FileNotFoundModule.RedirectUrlFormat,RedirectUrl,string.Empty);
                return HttpContext.Current.Request.Url.ToString().Contains(checkUrl);
            }
        }
    
        private CustomErrorsSection ConfigurationSecion
        {
            get
            {
                if (_configurationSection == null)
                {
                    _configurationSection = (CustomErrorsSection)WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath).GetSection("system.web/customErrors");
                }
                return _configurationSection;
            }
        }
    
        private string RedirectUrl
        {
            get
            {
                foreach (CustomError error in ConfigurationSecion.Errors)
                {
                    if (error.StatusCode == 404)
                    {
                        return error.Redirect;
                    }
                }
                return string.Empty;
            }
        }
    }
    

    Works for me 🙂

    /Viktor

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

Sidebar

Related Questions

I have added the following configuration section to my web.config file <security> <authentication> <anonymousAuthentication
i have the following piece of code my my web.config: <customErrors mode=On defaultRedirect=~/Exception.aspx enableVersionHeader=false>
I'm all of a sudden getting the following error with my Web.config file and
I get the following error while transforming a web.config file in TeamCity. It happens
I've inherited some aspx (including the web.config file) and am getting the following error.
I have a Service Application which has the following web.config file: <?xml version=1.0?> <configuration>
I have the following ASP.NET Membership section defined in the Web.config file: <membership defaultProvider=AspNetActiveDirectoryMembershipProvider>
I have added the following to my web.config file in my asp.net mvc3, to
So my Web.Config File has: <authentication mode=Forms> <forms loginUrl=~/Home/Index timeout=2880 /> </authentication> in my
i have a web.config file that looks like this: <?xml version=1.0?> <configuration> <system.web> <compilation

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.