示例#1
0
 public static void Log404Error(string msg)
 {
     if (MemCache.IsLoggingErrors)
     {
         Log404PageNotFound.Insert(DateTime.UtcNow, CurrentUrl, msg);
     }
 }
示例#2
0
        public static void OnApplicationError(HttpApplication application)
        {
            try
            {
                var path  = HttpContext.Current.Request.Path;
                var url   = path;
                var query = HttpContext.Current.Request.QueryString.ToString();
                if (!IsNullOrEmpty(query))
                {
                    url = url + '?' + query;
                }

                // check for embedded url
                if (EmbeddedUrlRegex.Match(path)
                    .Success) // redirect to real url
                {
                    application.Response.Redirect(Uri.UriSchemeHttp + "://" + url.Substring(1), true);
                    return;
                }

                if (application.Context.Error != null)
                {
                    if (
                        application.Context.Error.Message.StartsWith("A potentially dangerous Request.Path value was detected from the client", StringComparison.Ordinal) &&
                        HttpUtility.UrlDecode(path) == path)
                    {
                        application.Response.RedirectPermanent(
                            HttpContext.Current.Request.Url.AbsoluteUri, true);
                    }
                    else
                    {
                        Log404PageNotFound.Log("Global.asax Application_Error: " + application.Context.Error.Message);
                    }
                }
                else
                {
                    Log404PageNotFound.Log("Global.asax Application_Error");
                }
            }
            catch
            {
                // ignored
            } // no exceptions may be thrown here
        }