本文整理汇总了C#中System.Web.HttpContextBase.GetPortalContext方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.GetPortalContext方法的具体用法?C# HttpContextBase.GetPortalContext怎么用?C# HttpContextBase.GetPortalContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContextBase
的用法示例。
在下文中一共展示了HttpContextBase.GetPortalContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRouteData
public override RouteData GetRouteData(HttpContextBase httpContext)
{
PortalRequestContext context = httpContext.GetPortalContext();
if(context.ActivePage != null) {
return null;
}
string pagePath = httpContext.Request.AppRelativeCurrentExecutionFilePath;
// Normalize path to the form: /Segment/Segment/Segment
pagePath = NormalizePagePath(pagePath);
// Search for the page
Page page = PageRepository.GetLongestPrefixMatch(pagePath);
// If there is no matching page, return null
if(page == null) {
return null;
}
// Set the page in the context
context.ActivePage = page;
// Remove the actual page path and set as the new app-relative path
string appRelativePath = pagePath.Substring(page.Path.Length);
// Rewrite and reroute the request
// TODO: Can HttpContext.RewritePath do what we need? I do want to preserve the old HttpContext for use after routing
HttpContextBase rewrittenContext = new RewrittenHttpContext(httpContext, appRelativePath);
return RerouteRequest(r => r.GetRouteData(rewrittenContext));
}
示例2: GetRouteData
public override RouteData GetRouteData(HttpContextBase httpContext)
{
PortalRequestContext portalRequestContext = httpContext.GetPortalContext();
if(httpContext.HasPortalContext() && portalRequestContext.ActivePortal != null) {
return null; // Portal has already been specified, bypass this pre-router
}
Uri requestUrl = httpContext.Request.Url;
PortalPrefix prefix = PortalPrefixRepository.GetLongestPrefixMatch(requestUrl);
if(prefix == null || prefix.Portal == null) {
return null;
}
portalRequestContext.ActivePortal = prefix.Portal;
portalRequestContext.ActivePortalPrefix = prefix;
// Determine the Portal-relative url
string portalRelativeUrl = ExtractPortalRelativeUrl(requestUrl, prefix);
// Rewrite and re-route the request
// TODO: Can HttpContext.RewritePath do what we need? I do want to preserve the old HttpContext for use after routing
HttpContextBase rewrittenContext = new RewrittenHttpContext(httpContext, portalRelativeUrl);
return RerouteRequest(route => route.GetRouteData(rewrittenContext));
}
示例3: SetActivePortalPrefix
private static void SetActivePortalPrefix(HttpContextBase httpContext, string prefix)
{
httpContext.GetPortalContext().ActivePortalPrefix = new PortalPrefix {Id = 1, Prefix = prefix};
}