Refactoring ErrorController to return a HttpNotFound result, which will be

intercepted by the UnhandledExceptionFilter, in order to remove code ducplication.

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-02-23 14:29:37 -08:00
parent 5c3f281d44
commit 3d1018c866

View File

@@ -1,36 +1,12 @@
using System.Net;
using System.Web.Mvc;
using Orchard.Mvc;
using System.Web.Mvc;
using Orchard.Themes;
namespace Orchard.Core.Common.Controllers {
[Themed]
public class ErrorController : Controller {
private readonly IOrchardServices _orchardServices;
public ErrorController(IOrchardServices orchardServices) {
_orchardServices = orchardServices;
}
public ActionResult NotFound(string url) {
Response.StatusCode = (int)HttpStatusCode.NotFound;
var model = _orchardServices.New.NotFound();
if(url == null) {
url = Request.Url.OriginalString;
}
// If the url is relative then replace with Requested path
model.RequestedUrl = Request.Url.OriginalString.Contains(url) & Request.Url.OriginalString != url ?
Request.Url.OriginalString : url;
// Dont get the user stuck in a 'retry loop' by
// allowing the Referrer to be the same as the Request
model.ReferrerUrl = Request.UrlReferrer != null &&
Request.UrlReferrer.OriginalString != model.RequestedUrl ?
Request.UrlReferrer.OriginalString : null;
return new ShapeResult(this, model);
return HttpNotFound();
}
}
}