本文整理汇总了C#中Umbraco.Web.Routing.PublishedContentRequest.SetRedirectPermanent方法的典型用法代码示例。如果您正苦于以下问题:C# PublishedContentRequest.SetRedirectPermanent方法的具体用法?C# PublishedContentRequest.SetRedirectPermanent怎么用?C# PublishedContentRequest.SetRedirectPermanent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Umbraco.Web.Routing.PublishedContentRequest
的用法示例。
在下文中一共展示了PublishedContentRequest.SetRedirectPermanent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryFindContent
public override bool TryFindContent(PublishedContentRequest contentRequest)
{
// eg / or /path/to/whatever
var url = contentRequest.Uri.GetAbsolutePathDecoded();
var mdRoot = "/" + MarkdownLogic.BaseUrl;
if (url.StartsWith("/projects/umbraco-pro/contour/documentation"))
mdRoot = "/projects";
// ensure it's a md url
if (url.StartsWith(mdRoot) == false)
return false; // not for us
// find the root content
var node = FindContent(contentRequest, mdRoot);
if (node == null)
return false;
// kill those old urls
foreach (var s in new []{ "master", "v480" })
if (url.StartsWith(mdRoot + "/" + s))
{
url = url.Replace(mdRoot + "/" + s, mdRoot);
contentRequest.SetRedirectPermanent(url);
return true;
}
// find the md file
var mdFilepath = FindMarkdownFile(url);
if (mdFilepath == null)
{
// clear the published content (that was set by FindContent) to cause a 404, and in
// both case return 'true' because there's no point other finders try to handle the request
contentRequest.PublishedContent = null;
return true;
}
// set the context vars
var httpContext = contentRequest.RoutingContext.UmbracoContext.HttpContext;
httpContext.Items[MarkdownLogic.MarkdownPathKey] = mdFilepath;
httpContext.Items["topicTitle"] = string.Join(" - ", httpContext.Request.RawUrl
.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
.Skip(1)
.Reverse());
// override the template
const string altTemplate = "DocumentationSubpage";
var templateIsSet = contentRequest.TrySetTemplate(altTemplate);
//httpContext.Trace.Write("Markdown Files Handler",
// string.Format("Template changed to: '{0}' is {1}", altTemplate, templateIsSet));
// be happy
return true;
}
示例2: TryFindContent
public bool TryFindContent(PublishedContentRequest request)
{
//Get the requested URL path + query
var path = request.Uri.PathAndQuery.ToLower();
//Check the table
var matchedRedirect = RedirectRepository.FindRedirect(path);
if (matchedRedirect == null) return false;
//Found one, set the 301 redirect on the request and return
request.SetRedirectPermanent(matchedRedirect.NewUrl);
return true;
}