Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using wildcard query string / additional path has gone #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/NotFoundPageAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,39 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)

CustomRedirectHandler current = CustomRedirectHandler.Current;
CustomRedirect redirect = current.CustomRedirects.Find(HttpUtility.HtmlEncode(urlNotFound.AbsoluteUri));
string oldUrl = HttpUtility.HtmlEncode(urlNotFound.PathAndQuery);

string oldUrl = HttpUtility.HtmlEncode(urlNotFound.LocalPath);
if (redirect == null)
redirect = current.CustomRedirects.Find(oldUrl);

if (redirect != null)
if (redirect == null)
{
if (redirect.State.Equals(0) && (string.Compare(redirect.NewUrl, oldUrl, StringComparison.InvariantCultureIgnoreCase) != 0))
{
Log.Info(string.Format("404 Custom Redirect: To: '{0}' (from: '{1}')", redirect.NewUrl, oldUrl));
filterContext.Result = new RedirectResult(redirect.NewUrl, true);
return;
}
if ((Configuration.Configuration.Logging == LoggerMode.On) && Upgrader.Valid)
Logger.LogRequest(oldUrl, referer);

filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
filterContext.HttpContext.Response.StatusCode = 0x194;
filterContext.HttpContext.Response.Status = "404 File not found";
}
else if ((Configuration.Configuration.Logging == LoggerMode.On) && Upgrader.Valid)
else //redirect found
{
Logger.LogRequest(oldUrl, referer);
}
string newurl = redirect.NewUrl;
if (redirect.WildCardSkipAppend) //if wildcard, replace the 'old part' of url
{
newurl = urlNotFound.LocalPath.Replace(redirect.OldUrl, redirect.NewUrl);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always the desired outcome with wildcard URLs? This expects the URL-structure to be identical on both ends, doesn't it?

}

//always add querystring
newurl += urlNotFound.Query;

filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
filterContext.HttpContext.Response.StatusCode = 0x194;
filterContext.HttpContext.Response.Status = "404 File not found";
if (redirect.State.Equals(0) && (string.Compare(newurl, oldUrl, StringComparison.InvariantCultureIgnoreCase) != 0))
{
Log.Info(string.Format("404 Custom Redirect: To: '{0}' (from: '{1}')", newurl, oldUrl));

filterContext.Result = new RedirectResult(newurl, true);
}
}
}

}
}