本文整理匯總了C#中Umbraco.Web.Routing.PublishedContentRequest.SetResponseStatus方法的典型用法代碼示例。如果您正苦於以下問題:C# PublishedContentRequest.SetResponseStatus方法的具體用法?C# PublishedContentRequest.SetResponseStatus怎麽用?C# PublishedContentRequest.SetResponseStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Umbraco.Web.Routing.PublishedContentRequest
的用法示例。
在下文中一共展示了PublishedContentRequest.SetResponseStatus方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TryFindContent
public bool TryFindContent(PublishedContentRequest contentRequest)
{
//Check request is a 404
if (contentRequest.Is404)
{
//Get the home node
var home = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetAtRoot().Single(x => x.DocumentTypeAlias == "CWS-Home");
//Get the 404 node
var notFoundNode = home.Children.Single(x => x.DocumentTypeAlias == "CWS-404");
//Set Response Status to be HTTP 404
contentRequest.SetResponseStatus(404, "404 Page Not Found");
//Set the node to be the not found node
contentRequest.PublishedContent = notFoundNode;
}
//Not sure about this line - copied from Lee K's GIST
//https://gist.github.com/leekelleher/5966488
return contentRequest.PublishedContent != null;
}
示例2: TryFindContent
public bool TryFindContent(PublishedContentRequest contentRequest)
{
if (contentRequest.Is404)
{
contentRequest.SetResponseStatus(404, "404 Page Not Found");
var page404 = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetAtRoot().DescendantsOrSelf("CustomError").FirstOrDefault(c => c.Name.Contains("404"));
contentRequest.PublishedContent = page404;
}
return contentRequest.PublishedContent != null;
}