mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 19:44:02 +08:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user