Table of Contents
methods provided below. One
Method 2:
Home Web Front-end H5 Tutorial In-depth analysis of mvc4 custom 404 page in asp.net (share)

In-depth analysis of mvc4 custom 404 page in asp.net (share)

Aug 27, 2021 am 11:11 AM
asp.net css html js

In the previous article "An article explaining the usage of ES6 proxy Proxy in JS (code sharing)", we learned about the usage of ES6 proxy Proxy in JS. The following article will help you understand the mvc4 custom 404 page in asp.net. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In-depth analysis of mvc4 custom 404 page in asp.net (share)

#Of course there are many ways to define 404. Different methods present different forms, and the user experience is also different. There are two

methods provided below. One

1. Find the section <system.web> in web.config and click to enable404Configuration

<customErrors defaultRedirect="~/Error" mode="On" redirectMode="ResponseRedirect">
<error redirect="/Error" statusCode="404" />
</customErrors>

2. Define a controllersError (this is up to you), and define <pre class='brush:php;toolbar:false;'>public ActionResult Index() { Response.Status = &quot;404 Not Found&quot;; Response.StatusCode = 404; return View(); }</pre>this in

action

as follows This method defaults to adding ?aspxerrorpath=/ to your url. For example: http://localhost/Error??aspxerrorpath=/123456, so it is not recommended. Try

Method 2:

OpenGlobal.asaxFile definition error redirection address(controller/action)

protected void Application_Error(object sender, EventArgs e)
{
    Exception ex = Server.GetLastError();
    if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
    {
        Response.Redirect("/Error");
    }
}

Note: During development, we often use the Response.Redirect method in the Application_Error method in Global.asax to jump to a custom error page, but sometimes (especially when the site is deployed to IIS) the Response.Redirect method used in the Application_Error method will fail. When an abnormal error occurs, the default error yellow pages will still be displayed.

The fundamental reason is that although we used the Response.Redirect method in the Application_Error method, when an exception error occurs in the systemAsp.Net believes that the exception has not been handled, so it will not jump to the page pointed to by Response.Redirect in the Application_Error method, and will eventually jump to the default error Yellow Pages.

The solution to this problem is very simple to use Response.Redirect in the Application_Error method before calling The Server.ClearError() method tells the system that the abnormal error that occurred has been handled, so that if the Response.Redirect method is called again, the system will jump to the custom error page.

Recommended learning: asp.net video tutorial

The above is the detailed content of In-depth analysis of mvc4 custom 404 page in asp.net (share). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1503
276
What is the purpose of the rel attribute in a link tag in HTML? What is the purpose of the rel attribute in a link tag in HTML? Aug 03, 2025 pm 04:50 PM

rel="stylesheet"linksCSSfilesforstylingthepage;2.rel="preload"hintstopreloadcriticalresourcesforperformance;3.rel="icon"setsthewebsite’sfavicon;4.rel="alternate"providesalternateversionslikeRSSorprint;5.rel=&qu

What is the CSS aspect-ratio property and how to use it? What is the CSS aspect-ratio property and how to use it? Aug 04, 2025 pm 04:38 PM

Theaspect-ratioCSSpropertydefinesthewidth-to-heightratioofanelement,ensuringconsistentproportionsinresponsivedesigns.1.Itisapplieddirectlytoelementslikeimages,videos,orcontainersusingsyntaxsuchasaspect-ratio:16/9.2.Commonusecasesincludemaintainingres

How to create a CSS-only accordion menu? How to create a CSS-only accordion menu? Aug 03, 2025 pm 01:48 PM

Use hidden checkboxes and CSS's :checked pseudo-class combined with adjacent sibling selectors ( ) to control content display; 2. The HTML structure contains input, label and content div for each collapsed item; 3. Smooth expansion/collapse animations by setting max-height transition; 4. Add open/close status icons with pseudo-elements; 5. Use radio types to implement single-open mode, while checkbox allows multiple openings. This is an interactive foldable menu implementation that requires no JavaScript and is compatible with modern browsers.

Is the longdesc attribute for HTML images still useful Is the longdesc attribute for HTML images still useful Aug 03, 2025 pm 02:15 PM

Thelongdescattributeisobsoleteduetopoorbrowserandscreenreadersupport,oftenleavingusersunawareofavailabledetaileddescriptions.2.Modernalternativeslikeinlinedescriptions,aria-describedby,semanticHTMLelementssuchasfigureandfigcaption,andexpandableconten

How to use CSS clip-path for creative shapes? How to use CSS clip-path for creative shapes? Aug 04, 2025 pm 02:55 PM

Use CSSclip-path to create non-rectangular shapes in the browser without additional images or complex SVG; 2. Common shape functions include inset(), circle(), ellipse() and polygon(), where polygon() implements custom shapes by defining coordinate points, which is suitable for creating creative designs such as dialog bubbles; 3. clip-path can achieve dynamic effects through CSS transition or keyframe animation, such as circle expansion during hovering, but only supports inter-shape animations of the same type and number of vertices; 4. Pay attention to responsiveness and accessibility to ensure that the content is still available when not supported, the text is readable, avoid excessive cropping, and control the number of polygon vertices to optimize performance. At the same time, it is necessary to know that

How to highlight text with the  tag? How to highlight text with the tag? Aug 04, 2025 pm 04:29 PM

Use tags to highlight text semantically, often used to identify search results or important content; 2. Custom styles such as background colors, text colors and borders can be customized through CSS; 3. It should be used in contexts with practical significance, rather than just visual decoration to improve accessibility and SEO effects.

How to use HTML to create a link that opens in a new tab How to use HTML to create a link that opens in a new tab Aug 05, 2025 am 04:29 AM

To safely open a link in a new tab, you need to use target="_blank" and always cooperate with rel="noopener". You can choose rel="noreferrer" to enhance privacy protection. The specific steps are: 1. Use href to set the target URL; 2. Add target="_blank" to open the link in a new tab; 3. Add rel="noopener" to prevent the new page from manipulating the original page and improving performance; 4. You can choose rel="noreferrer" to prevent sending

How to use the CSS :empty pseudo-class? How to use the CSS :empty pseudo-class? Aug 05, 2025 am 09:48 AM

The:emptypseudo-classselectselementswithnochildrenorcontent,includingspacesorcomments,soonlytrulyemptyelementslikematchit;1.Itcanhideemptycontainersbyusing:empty{display:none;}tocleanuplayouts;2.Itallowsaddingplaceholderstylingvia::beforeor::after,wh

See all articles