public static bool HandleRequest(string referer, Uri urlNotFound, out CustomRedirect foundRedirect)
{
// Try to match the requested url my matching it
// to the static list of custom redirects
CustomRedirectHandler fnfHandler = CustomRedirectHandler.Current;
CustomRedirect redirect = fnfHandler.CustomRedirects.Find(urlNotFound);
string pathAndQuery = urlNotFound.PathAndQuery;
foundRedirect = null;
if (redirect == null)
{
redirect = fnfHandler.CustomRedirects.FindInProviders(urlNotFound.AbsoluteUri);
}
if (redirect != null)
{
// Url has been deleted from this site
if (redirect.State.Equals((int)DataStoreHandler.State.Deleted))
{
foundRedirect = redirect;
return true;
}
if (redirect.State.Equals((int)DataStoreHandler.State.Saved))
{
// Found it, however, we need to make sure we're not running in an
// infinite loop. The new url must not be the referrer to this page
if (string.Compare(redirect.NewUrl, pathAndQuery, StringComparison.InvariantCultureIgnoreCase) != 0)
{
foundRedirect = redirect;
return true;
}
}
}
else
{
// log request to database - if logging is turned on.
if (Configuration.Configuration.Logging == LoggerMode.On)
{
// Safe logging
RequestLogger.Instance.LogRequest(pathAndQuery, referer);
}
}
return false;
}