我从Stackoverflow->博客重新处理Sitecore中的自定义404(它实际上做302重定向到状态200的404页面,它被google作为软404获取) 。生产中的Sitecore自定义404处理程序
虽然这在我们的本地测试服务器中完全正常,但当我们在生产中丢弃该网站时,网站出现故障并需要AGES 8-9分钟加载和东西。
public class ExecuteRequest : Sitecore.Pipelines.HttpRequest.ExecuteRequest
{
protected override void RedirectOnItemNotFound(string url)
{
var context = System.Web.HttpContext.Current;
try
{
// Request the NotFound page
var domain = context.Request.Url.GetComponents(
UriComponents.Scheme | UriComponents.Host,
UriFormat.Unescaped);
var content = WebUtil.ExecuteWebPage(
string.Concat(domain, url));
// The line below is required for IIS 7.5 hosted
// sites or else IIS is gonna display default 404 page
context.Response.TrySkipIisCustomErrors = true;
context.Response.StatusCode = 404;
context.Response.Write(content);
}
catch (Exception ex)
{
Log.Error(string.Format("Falling back to default redirection behavior. Reason for error {0}", ex), ex);
// Fall back to default behavior on exceptions
base.RedirectOnItemNotFound(url);
}
context.Response.End();
}
}
P.S:然后我在web.config中用我自定义的一个替换了ExecuteRequest。
如果您遇到类似的事情或知道任何问题,请务必澄清一些情况。
在此先感谢
我曾想过对WebUtil.ExecuteWebPage的调用在任何其他轻量级流量中都会产生问题。太多的循环Web请求触发。如果你的404页面以某种方式调用404本身,你可能会进入循环(也许这是发生了什么?) – 2013-04-18 08:53:31