Browse Source

Added IP and Referel url to error email

master
Teknikode 6 years ago
parent
commit
8c4be85ba9
  1. 2
      Teknik/App_Start/SubdomainRoute.cs
  2. 21
      Teknik/Areas/Error/Controllers/ErrorController.cs

2
Teknik/App_Start/SubdomainRoute.cs

@ -47,8 +47,8 @@ namespace Teknik @@ -47,8 +47,8 @@ namespace Teknik
if (routeData == null) return null; // Only look at the subdomain if this route matches in the first place.
string subdomain = httpContext.Request.QueryString["sub"]; // A subdomain specified as a query parameter takes precedence over the hostname.
string host = httpContext.Request.Headers["Host"];
string curSub = host.GetSubdomain();
string domain = host.GetDomain();
string curSub = host.GetSubdomain();
// special consideration for 'dev' subdomain
if (subdomain == null || subdomain == "dev")

21
Teknik/Areas/Error/Controllers/ErrorController.cs

@ -148,8 +148,10 @@ namespace Teknik.Areas.Error.Controllers @@ -148,8 +148,10 @@ namespace Teknik.Areas.Error.Controllers
Message: {0}
Source: {1}
IP Address: {2}
Referer Address: {3}
Stack Trace: {2}", ex.GetFullMessage(true), ex.Source, ex.StackTrace);
Stack Trace: {4}", ex.GetFullMessage(true), ex.Source, GetIPAddress(), Request.UrlReferrer.AbsoluteUri, ex.StackTrace);
mail.BodyEncoding = UTF8Encoding.UTF8;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
@ -157,5 +159,22 @@ Stack Trace: {2}", ex.GetFullMessage(true), ex.Source, ex.StackTrace); @@ -157,5 +159,22 @@ Stack Trace: {2}", ex.GetFullMessage(true), ex.Source, ex.StackTrace);
}
catch (Exception) { /* don't handle something in the handler */ }
}
private string GetIPAddress()
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ipAddress))
{
string[] addresses = ipAddress.Split(',');
if (addresses.Length != 0)
{
return addresses[0];
}
}
return context.Request.ServerVariables["REMOTE_ADDR"];
}
}
}
Loading…
Cancel
Save