I'm using MVC in Umbraco 6. I am trying to get the configured Umbraco 404 page to render following some condition in a child action.
I'm calling a child action from one of my templates:
@Html.Action("ShowBoatDetails", "Boat");
Here's the child action in the controller:
public class BoatController : SurfaceController { [ChildActionOnly] public ActionResult ShowBoatDetails() { if (SomeCondition) { return HttpNotFound(); }
var model = new BoatModel();
return PartialView("BoatDetails", model); } }
It is when SomeCondition is true, I am trying to get the child action to render the configured umbraco 404 page. What is currently happening is that a 404 status code is returned, but the rest of the page continues to render as normal - the umbraco 404 page is not shown.
And the 404 now renders correctly when called from the child action, however 500 server errors are now showing a very basic error page with no error details (not the normal YSOD).
When you say basic errors what are these? You can this in IIS. or could catch some error in your controller and set the status to 500 and return a responce. Charlie :)
Right, well you could handel tthe 500 error in your code for instance. I believe the problem is the YSOD error is futher down the call stack than those custom errors. You can call Server.GetLastError() and then throw that error when you come across a 500? Never tried this but in theroy it works. Charlie
The thing is I don't know where the 500 errors might come up at this stage, so for debugging purposes the YSOD is helpful. Or are you thinking of some kind of global catchall for 500 errors? Do you think that it might get to a recursive situation where it catches a 500 and then throws it, then catches it and throws it...etc
It what situation did you you consider a recursive situation? If you had it in your model and you threw a new error passing in the Server.GetLastError(), then the error should be displayed?
MVC - return 404 from child action
I'm using MVC in Umbraco 6. I am trying to get the configured Umbraco 404 page to render following some condition in a child action.
I'm calling a child action from one of my templates:
Here's the child action in the controller:
It is when SomeCondition is true, I am trying to get the child action to render the configured umbraco 404 page. What is currently happening is that a 404 status code is returned, but the rest of the page continues to render as normal - the umbraco 404 page is not shown.
Edit
I set my web.config to the following:
And the 404 now renders correctly when called from the child action, however 500 server errors are now showing a very basic error page with no error details (not the normal YSOD).
You can either add a error statusCode for the 500
When you say basic errors what are these? You can this in IIS. or could catch some error in your controller and set the status to 500 and return a responce. Charlie :)
Thanks for the response. I was just seeing the default IIS 500 error page rather than a YSOD with error details.
So I have decided to, as you suggest, add a 500 error statusCode.
However, I decided it was best just to add this only in release mode for production so that I can still see YSODs in debug mode.
Thanks,
Michael
Right, well you could handel tthe 500 error in your code for instance. I believe the problem is the YSOD error is futher down the call stack than those custom errors. You can call Server.GetLastError() and then throw that error when you come across a 500? Never tried this but in theroy it works. Charlie
The thing is I don't know where the 500 errors might come up at this stage, so for debugging purposes the YSOD is helpful. Or are you thinking of some kind of global catchall for 500 errors? Do you think that it might get to a recursive situation where it catches a 500 and then throws it, then catches it and throws it...etc
It what situation did you you consider a recursive situation? If you had it in your model and you threw a new error passing in the Server.GetLastError(), then the error should be displayed?
is working on a reply...