来自项目的Sitecore 404页面

来自项目的Sitecore 404页面,sitecore,sitecore7,sitecore7.2,Sitecore,Sitecore7,Sitecore7.2,让Sitecore以404错误代码响应似乎是最受关注的问题,其中处理器被添加到httpRequestBegin管道中,并且StatusCode被设置为404,而响应是根据单独请求的结果写入的。像这样: //请求NotFound页面 string domain=context.Request.Url.GetComponents(UriComponents.Scheme | UriComponents.Host,UriFormat.Unescaped); string content=Sitecor

让Sitecore以404错误代码响应似乎是最受关注的问题,其中处理器被添加到
httpRequestBegin
管道中,并且
StatusCode
被设置为404,而响应是根据单独请求的结果写入的。像这样:

//请求NotFound页面
string domain=context.Request.Url.GetComponents(UriComponents.Scheme | UriComponents.Host,UriFormat.Unescaped);
string content=Sitecore.Web.WebUtil.ExecuteWebPage(string.Concat(域,url));
//使用404状态代码将NotFound页面内容发送到客户端
context.Response.tryskipiiscustomerors=true;
context.Response.StatusCode=404;
context.Response.Write(内容);
这个解决方案对我来说效果不好,因为当服务器再次请求获取404内容时,cookie/安全性和IP检测就会丢失

在与Sitecore的支持进行了反复讨论之后,我们得出了以下代码(只是一个简单的示例):

公共类MyHttpBeginRequestProcessor:Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
公共覆盖无效进程(Sitecore.Pipelines.HttpRequest.HttpRequestArgs)
{
if(Sitecore.Context.Item!=null
||Sitecore.Context.Site==null
||Sitecore.Context.Database==null)
{
返回;
}
Sitecore.Data.Database master=Sitecore.Configuration.Factory.GetDatabase(“master”);
Sitecore.Context.Item=master.GetItem(“/Sitecore/content/home”);
Sitecore.Context.Items[“Set404”]=“true”;
}
}
公共类MyHttpEndRequestProcessor:Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
公共覆盖无效进程(Sitecore.Pipelines.HttpRequest.HttpRequestArgs)
{
if(Sitecore.Context.Items.Contains(“Set404”))
{
args.Context.Response.StatusCode=404;
}
}
}
然后在
httpRequestEnd
管道以及
httpRequestBegin
管道中放置一个新处理器,如下所示:


这在我的本地工作站(Win7 x64)上运行良好;但是,当我将站点复制到Win2008 x64服务器时,将显示默认的IIS 404错误页面。在
httpRequestEnd
管道上将StatusCode设置为404会导致IIS显示其404错误,而不是我在
httpRequestBegin
管道中设置的Sitecore项目

Sitecore支持说操作系统不重要,它在Win2008服务器上对他们有效,但我尝试了4台独立的Win2008机器,我尝试了Sitecore 7.2版本的普通安装。141226,每次都会显示默认的IIS 404错误


有什么想法吗?谢谢将以下内容添加到您的代码中:

context.Response.TrySkipIisCustomErrors = true;