Who owns vin 1D37H2B653127?

jimmy hendrix



How to handle 500 server errors in Umbraco

I just want a custom error page when a server error occurs - I've tried endless combinations of suggestions that I've found on google but nothing even begins to get me there.



Essentially, I have some error handling routines in my surface controllers where I want to log the error & then throw the exception so that somewhere down the line a 500 response code is returned & a custom error page is displayed.



                try
{
repository.AddShoppingCartItem(sci);
}
catch(Exception e)
{
Log.Error("whatever...");
throw;
}


Then in my web.config I've tried



   <customErrors mode="On" defaultRedirect="error500">
</customErrors>


and



   <customErrors mode="On" defaultRedirect="umbraco/surface/error500surface">
</customErrors>


(where the 1st version uses a regular controller & the second a surface controller)



Neither do anything.



I've also added this line as others have suggested but it makes no difference:



What I get is my normal layout page getting rendered along with this message:



Error loading Partial View script (file: ~/Views/MacroPartials/Addcart.cshtml)



what I want to happen is for a custom error page to be displayed instead.



Reading all the stuff on google, I'm completely confused as to whether I need to configure Umbraco to handle these errors or whether it's a pure MVC approach. I get the impression that 404 errors are done through umbraco but 500 errors need to be a pure MVC approach. Don't know if anyone can confirm this. Either way, something up the chain is swallowing my throw statement & I don't know what it is.



I've also tried



return new HttpStatusCodeResult(500);



in place of the throw & that just gets me a nasty IIS error page.



Any help would be most appreciated as this is driving me nuts.



Answers

500 errors are server errors and no different in Umbraco than in regular IIS:




This is a server error and can only be solved by website admin who has access to files and the web-server. There can be one of/or multiple reasons to get this error. One has to track down the issue and handle accordingly.




http://www.codeproject.com/Articles/545054/HTTPplus-plus-e-plusInternalplusserverplus



More info:
http://serverfault.com/questions/407954/how-to-diagnose-a-500-internal-server-error-on-iis-7-5-when-nothing-is-written-t



Edit: apparently you may be able to enable custom errors like so:

http://helpnotes.vpasp.com/kb/611-General-hosting-questions/1089-How-to-Turn-Off-Friendly-Error-in-IIS-7xx/



Edit2: This may be of interest as well:

http://benfoster.io/blog/aspnet-mvc-custom-error-pages





'Class not found' even though file is properly included

So I have a really simple set of files:



main.php



include_once 'User.php';

echo 'im here'; //never reached!

$user = new My\Test\User();

...


User.php



namespace My\Test;

include_once 'Student.php';

class User {...}


Student.php



namespace My\Test;

include_once 'User.php';

var_dump(in_array('User.php', get_included_files())); //true

var_dump(class_exist('User')); //false
var_dump(class_exist('\My\Namespace\User')); //false
var_dump(class_exist('My\Namespace\User')); //false - How can that be?

class Student extends User {...} //Fatal Error: Class My\Namespace\User not found


So what happens here is that the User class is included first from main.php. Because it has some static methods that create Students instances aswell it needs to include the Students class file. The Students file, as it extends User, includes User.php aswell, but that should not be executed, since I used include_once. I even check if the file was included properly, yet a few lines later I get the fatal error. Both files have the same namespace.



Whats funny is that before I applied namespaces to my classes everything worked, so I assume it is some kind of bug with cross-including files with the same namespace.



Tried to remove the include_once from Student.php, it makes no difference.



If main.php includes User.php, and User.php includes Student.php, why cant Student.php not find the User class?!



I'm on PHP Version 5.5.9



Answers

Your main.php is not operating within the correct namespace, when it is calling to create a new User();.



You need to specify the namespace in main.php, or otherwise use the correct namespace (I named the namespace MyNamespace - since your pseudo code had an invalid namespace name of Namespace).



<?php
namespace MyNamespace;

include_once 'User.php';

echo 'im here'; //never reached!

$user = new User();


Once you change to this you get:



Scotts-rMBP-3:bar smoore$ php main.php 
bool(false)
bool(false)
bool(true)
bool(true)
im here




↑このページのトップヘ