mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed NotFound method not logging correct info/returning 404 status
This commit is contained in:
parent
a69369e813
commit
ba4c3030ff
@ -145,7 +145,12 @@ namespace Teknik.Areas.Error.Controllers
|
||||
errorMessage += " for page: " + Request.Url.AbsoluteUri;
|
||||
}
|
||||
|
||||
errorMessage += " - using Method: " + Request.HttpMethod;
|
||||
if (Request.UrlReferrer != null)
|
||||
{
|
||||
errorMessage += " | for referred page: " + Request.Url.AbsoluteUri;
|
||||
}
|
||||
|
||||
errorMessage += " | using Method: " + Request.HttpMethod;
|
||||
}
|
||||
|
||||
Logger.WriteEntry(LogLevel.Warning, errorMessage, exception);
|
||||
@ -182,21 +187,5 @@ namespace Teknik.Areas.Error.Controllers
|
||||
|
||||
return View("~/Areas/Error/Views/Error/Http500.cshtml", model);
|
||||
}
|
||||
|
||||
private string GetIPAddress()
|
||||
{
|
||||
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
||||
|
||||
if (!string.IsNullOrEmpty(ipAddress))
|
||||
{
|
||||
string[] addresses = ipAddress.Split(',');
|
||||
if (addresses.Length != 0)
|
||||
{
|
||||
return addresses[0];
|
||||
}
|
||||
}
|
||||
|
||||
return Request.ServerVariables["REMOTE_ADDR"];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Teknik.Areas.Error.Controllers;
|
||||
using Teknik.Configuration;
|
||||
|
||||
@ -36,6 +37,8 @@ namespace Teknik.Controllers
|
||||
get { return HttpContext.User as TeknikPrincipal; }
|
||||
}
|
||||
|
||||
public object ObjectFactory { get; private set; }
|
||||
|
||||
public DefaultController()
|
||||
{
|
||||
ViewBag.Title = Config.Title;
|
||||
@ -47,6 +50,28 @@ namespace Teknik.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
protected override void HandleUnknownAction(string actionName)
|
||||
{
|
||||
this.InvokeHttp404(HttpContext);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public ActionResult InvokeHttp404(HttpContextBase httpContext)
|
||||
{
|
||||
IController errorController = new ErrorController();
|
||||
var errorRoute = new RouteData();
|
||||
errorRoute.DataTokens.Add("namespaces", new[] { typeof(ErrorController).Namespace });
|
||||
errorRoute.DataTokens.Add("area", "Error");
|
||||
errorRoute.Values.Add("controller", "Error");
|
||||
errorRoute.Values.Add("action", "Http404");
|
||||
errorRoute.Values.Add("exception", null);
|
||||
errorController.Execute(new RequestContext(
|
||||
httpContext, errorRoute));
|
||||
|
||||
return new EmptyResult();
|
||||
}
|
||||
|
||||
// Get the Favicon
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
@ -81,12 +106,7 @@ namespace Teknik.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult NotFound()
|
||||
{
|
||||
var errorController = new ErrorController();
|
||||
if (errorController != null)
|
||||
{
|
||||
return errorController.Http404(new Exception("Page Not Found"));
|
||||
}
|
||||
return null;
|
||||
return InvokeHttp404(HttpContext);
|
||||
}
|
||||
|
||||
protected ActionResult GenerateActionResult(object json)
|
||||
|
Loading…
Reference in New Issue
Block a user