custom-error-pages

Routing for custom ASP.NET MVC 404 Error page

强颜欢笑 提交于 2019-11-26 03:36:53
问题 I am trying to make a custom HTTP 404 error page when someone types in a URL that doesn\'t invoke a valid action or controller in ASP.NET MVC, instead of it displaying the generic \"Resource Not Found\" ASP.NET error. I don\'t want to use the web.config to handle this. Is there any kind of routing magic I can do to catch any invalid URLs? Update: I tried the answer given, however I still get the ugly \"Resource Not Found\" message. Another update: Ok, apparently something changed in RC1. I\

ASP.NET MVC HandleError

和自甴很熟 提交于 2019-11-26 03:02:52
How do I go about the [HandleError] filter in asp.net MVC Preview 5? I set the customErrors in my Web.config file <customErrors mode="On" defaultRedirect="Error.aspx"> <error statusCode="403" redirect="NoAccess.htm"/> <error statusCode="404" redirect="FileNotFound.htm"/> </customErrors> and put [HandleError] above my Controller Class like this: [HandleError] public class DSWebsiteController: Controller { [snip] public ActionResult CrashTest() { throw new Exception("Oh Noes!"); } } Then I let my controllers inherit from this class and call CrashTest() on them. Visual studio halts at the error

ASP.NET custom error page - Server.GetLastError() is null

北城以北 提交于 2019-11-26 01:49:16
问题 I have a custom error page set up for my application: <customErrors mode=\"On\" defaultRedirect=\"~/errors/GeneralError.aspx\" /> In Global.asax, Application_Error(), the following code works to get the exception details: Exception ex = Server.GetLastError(); if (ex != null) { if (ex.GetBaseException() != null) ex = ex.GetBaseException(); } By the time I get to my error page (~/errors/GeneralError.aspx.cs), Server.GetLastError() is null Is there any way I can get the exception details on the

ASP.NET MVC HandleError

混江龙づ霸主 提交于 2019-11-26 01:12:37
问题 How do I go about the [HandleError] filter in asp.net MVC Preview 5? I set the customErrors in my Web.config file <customErrors mode=\"On\" defaultRedirect=\"Error.aspx\"> <error statusCode=\"403\" redirect=\"NoAccess.htm\"/> <error statusCode=\"404\" redirect=\"FileNotFound.htm\"/> </customErrors> and put [HandleError] above my Controller Class like this: [HandleError] public class DSWebsiteController: Controller { [snip] public ActionResult CrashTest() { throw new Exception(\"Oh Noes!\"); }

ASP.NET custom error page - Server.GetLastError() is null

跟風遠走 提交于 2019-11-26 00:52:04
I have a custom error page set up for my application: <customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx" /> In Global.asax, Application_Error(), the following code works to get the exception details: Exception ex = Server.GetLastError(); if (ex != null) { if (ex.GetBaseException() != null) ex = ex.GetBaseException(); } By the time I get to my error page (~/errors/GeneralError.aspx.cs), Server.GetLastError() is null Is there any way I can get the exception details on the Error Page, rather than in Global.asax.cs ? ASP.NET 3.5 on Vista/IIS7 nailitdown Looking more closely at my