我从Stackoverflow->博客中拿起下面的代码重新处理自定义在Sitecore的404(它实际上可以做一个302重定向到404页与状态200得到由谷歌拿起软404).
虽然这在我们的本地测试服务器中完全正常,但是当我们将其放入生产中时,该站点变得混乱,并且需要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();
}
}
Run Code Online (Sandbox Code Playgroud)
PS:然后我用web.config中的自定义替换了ExecuteRequest.
如果您经历过类似的事情或者知道任何问题,请务必说清楚.
提前致谢
Sitecore中有一个设置,您可以使用它来摆脱302重定向:
<setting name="RequestErrors.UseServerSideRedirect" value="true" />
Run Code Online (Sandbox Code Playgroud)
使用此设置,URL保持不变,状态代码为404.如果您想要一些额外的逻辑(如将Sitecore项目显示为错误页面),则Sitecore Market Place上会有一个名为Error Manager的共享源模块.
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
3008 次 |
| 最近记录: |