In-depth analysis of mvc4 custom 404 page in asp.net (share)
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.
#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 enable404
Configuration
<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 = "404 Not Found";
Response.StatusCode = 404;
return View();
}</pre>
this in
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.asax
File 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 theApplication_Error
method inGlobal.asax
to jump to a custom error page, but sometimes (especially when the site is deployed to IIS) theResponse.Redirect
method used in theApplication_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 theApplication_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 byResponse.Redirect
in theApplication_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 theApplication_Error
method before callingThe Server.ClearError()
method tells the system that the abnormal error that occurred has been handled, so that if theResponse.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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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

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

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.

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

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

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.

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

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