BVNetwork.NotFound.Core.NotFoundPage.NotFoundPageUtil.GetUrlNotFound C# (CSharp) Method

GetUrlNotFound() public static method

Gets the URL that was not found.
public static GetUrlNotFound ( System.Web.HttpRequestBase request ) : string
request System.Web.HttpRequestBase The request.
return string
        public static string GetUrlNotFound(HttpRequestBase request)
        {
            string urlNotFound = null;
            string query = request.ServerVariables["QUERY_STRING"];
            if ((query != null) && query.StartsWith("4"))
            {
                string url = query.Split(';')[1];
                urlNotFound = HttpUtility.UrlDecode(url);
            }
            if (urlNotFound == null)
            {
                if (query.StartsWith("aspxerrorpath="))
                {
                    string[] parts = query.Split('=');
                    urlNotFound = request.Url.GetLeftPart(UriPartial.Authority) + HttpUtility.UrlDecode(parts[1]);
                }
            }
            return urlNotFound;
        }

Usage Example

Esempio n. 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (PageEditing.PageIsInEditMode)
            {
                return;
            }

            Logger.Debug("Starting 404 handler action filter");
            var request = filterContext.HttpContext.Request;

            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
            var statusCode = NotFoundPageUtil.GetStatusCode(request);

            filterContext.HttpContext.Response.StatusCode = statusCode;
            var status = NotFoundPageUtil.GetStatus(statusCode);

            if (!string.IsNullOrEmpty(status))
            {
                filterContext.HttpContext.Response.Status = status;
            }
            NotFoundPageUtil.SetCurrentLanguage(filterContext.HttpContext);
            filterContext.Controller.ViewBag.Referrer    = NotFoundPageUtil.GetReferer(request);
            filterContext.Controller.ViewBag.NotFoundUrl = NotFoundPageUtil.GetUrlNotFound(request);
            filterContext.Controller.ViewBag.StatusCode  = statusCode;
        }