Razor Redirect To Error Page
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn
Mvc Redirect To Error Page
more about Stack Overflow the company Business Learn more about hiring developers or posting mvc 5 custom error page ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Mvc 5 Redirect To Error Page
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Displaying custom error CSHTML page in MVC5 on 404 / mvc redirect to error page on exception 500 / any exception? up vote 2 down vote favorite 1 I have been pulling my hair out over this all day. I'm trying to just display a friendly cshtml page whenever an exception is thrown so my UX is consistent - I don't want my users even knowing I'm on the .net stack from the UI, ever. I'm testing by navigating to localhost:2922/junkurl, - if the URL does mvc 5 error handling not resolve, cannot be found, or otherwise generates an exception, I want to display a friendly rendered cshtml page. What I have in my web.config:
you're not alone. It's surprisingly difficult to do this correctly, not helped by the fact that some errors are handled by ASP.NET and others by IIS. Ideally (and I expect such is the case
Mvc 404 Error Handling
with some other frameworks/servers) we would just configure our custom error pages in one mvc custom error page not showing place and it would just work, no matter how/where the error was raised. Something like:
Mvc Handleerrorattribute
404 Page Not Found
http://benfoster.io/blog/aspnet-mvc-custom-error-pages I created a new ASP.NET MVC 5 application using the standard template in Visual Studio. If I run the site and try to navigate to a resource that does not exist e.g. /foo/bar, I'll get the standard ASP.NET 404 page with the following information: Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /foo/bar Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.33440 Not exactly friendly, is it? In this case the error was raised by ASP.NET MVC because it could not find a matching controller and/or action that matched the specified URL. In order to set up a custom 404 error page add the following to web.config insideASP.NET Razor Web Pages 1 Comment 10 March 2015 13:07 4.3 (10 votes) ASP.NET Web Pages WebMatrix Bang! An unhandled exception occurred during the execution of the current web request. And that's it - your visitor is met with the http://www.mikesdotnetting.com/article/266/error-handling-in-asp-net-razor-web-pages yellow screen of death and they are left wondering what they did wrong. You might http://www.devcurry.com/2012/06/aspnet-mvc-handling-exceptions-and-404.html not even be aware of what's just happened - unless your visitor can find some way of alerting you, oh, and they bother to do so. That's the problem with run time errors; the code worked fine when you ran it on your machine. But then along came a user and they tried to do something you didn't anticipate and broke error page your site. So what should you do about this? The key to managing the issue is understanding it. The kind of errors I'm discussing in this article fall into two distinct categories: runtime errors that result from assumptions you made in code that didn't cover all the bases; and ones that result from the unforeseen failure of dependencies. Let's first look at assumptions made in code. Here's a simple page with a form and a bit redirect to error of code to process the form's values when it is submitted. The code takes the numbers entered into each box and divides one by the other: @{ var result = string.Empty; if(IsPost){ result = (Request["a"].AsDecimal() / Request["b"].AsDecimal()).ToString(); } }