상속: IHttpActionContext
예제 #1
0
        private static string GetSmartUrl(PortalContext portalContext)
        {
            if (portalContext == null)
                throw new ArgumentNullException("portalContext");

            if (portalContext.SiteRelativePath == null)
                return null;

            if (portalContext.Site == null)
                return null;

            if (portalContext.Site.Path == null)
                return null;

            var siteRelativePath = portalContext.SiteRelativePath.ToLowerInvariant();
            var sitePath = portalContext.Site.Path.ToLowerInvariant();

            string smartUrlTargetPath;

            PortalContext.SmartUrls.TryGetValue(string.Concat(sitePath, ":", siteRelativePath), out smartUrlTargetPath);

            if (smartUrlTargetPath == null)
                return null;

            string resolvedSmartUrl = string.Concat(
                portalContext.OriginalUri.Scheme,
                "://",
                portalContext.SiteUrl,
                smartUrlTargetPath,
                portalContext.OriginalUri.Query
            );

            return resolvedSmartUrl;
        }
예제 #2
0
 private static IHttpAction GetDefaultContextAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, string actionName, string appNodePath)
 {
     if (String.IsNullOrEmpty(actionName) && String.IsNullOrEmpty(appNodePath))
     {
         if(!String.IsNullOrEmpty(portalContext.QueryStringNodePropertyName))
             return factory.CreateDownloadAction(portalContext, contextNode, null, GetRewritePath(contextNode, portalContext), portalContext.QueryStringNodePropertyName);
         var nodeType = contextNode.GetNodeType();
         if (nodeType.IsInstaceOfOrDerivedFrom("Page"))
             return factory.CreateRewriteAction(portalContext, contextNode, null, GetRewritePath(contextNode, portalContext));
         if (nodeType.IsInstaceOfOrDerivedFrom("File"))
             return factory.CreateDownloadAction(portalContext, contextNode, null, GetRewritePath(contextNode, portalContext), PortalContext.DefaultNodePropertyName);
     }
     return null;
 }
예제 #3
0
        //---------------------------------------------------------------------

        private static string GetRewritePath(NodeHead appNodeHead, PortalContext portalContext)
        {
            if (!String.IsNullOrEmpty(portalContext.QueryStringNodePropertyName))
                return appNodeHead.Path;
            
            NodeType contextNodeType = appNodeHead.GetNodeType();

            if (contextNodeType.IsInstaceOfOrDerivedFrom("Page"))
                return appNodeHead.Path + PortalContext.InRepositoryPageSuffix;
            //else if (contextNodeType.IsInstaceOfOrDerivedFrom("GenericContent") && !contextNodeType.IsInstaceOfOrDerivedFrom("File"))
            //    return appNodeHead.Path + PortalContext.InRepositoryPageSuffix;
            else if (contextNodeType.IsInstaceOfOrDerivedFrom("Site"))
                throw new NotSupportedException("/*!!!*/");

            return appNodeHead.Path;
        }
예제 #4
0
 private static IHttpAction GetIHttpHandlerAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, Type httpHandlerType)
 {
     return factory.CreateRemapAction(portalContext, contextNode, null, httpHandlerType);
 }
예제 #5
0
 private static IHttpAction GetIHttpHandlerAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, NodeHead handlerNode)
 {
     var nodeType = handlerNode.GetNodeType();
     Type appType = TypeHandler.GetType(nodeType.ClassName);
     if (typeof(IHttpHandler).IsAssignableFrom(appType))
         return factory.CreateRemapAction(portalContext, contextNode, null, handlerNode);
     return null;
 }
예제 #6
0
        private static IHttpAction GetExternalPageAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, string actionName, string appNodePath)
        {
            if (contextNode == null)
                return null;
            if (actionName != null)
                return null;
            if (appNodePath != null)
                return null;

            string outerUrl = null;
            AccessProvider.ChangeToSystemAccount();
            try
            {
                Page page = Node.LoadNode(contextNode.Id) as Page;
                if (page != null)
                    if (Convert.ToBoolean((page["IsExternal"])))
                        outerUrl = page.GetProperty<string>("OuterUrl");
            }
            finally
            {
                AccessProvider.RestoreOriginalUser();
            }
            if (outerUrl != null)
                return factory.CreateRedirectAction(portalContext, contextNode, null, outerUrl, false, true);
            return null;
        }
예제 #7
0
        private static IHttpAction GetWebdavAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            if (!portalContext.IsWebdavRequest)
                return null;

            return GetIHttpHandlerAction(factory, portalContext, contextNode, typeof(SenseNet.Services.WebDav.WebDavHandler));
        }
예제 #8
0
 private static IHttpAction GetSmartUrlAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
 {
     string smartUrl = GetSmartUrl(portalContext);
     if (smartUrl != null)
         return factory.CreateRedirectAction(portalContext, contextNode, null, smartUrl, false, true);
     return null;
 }
예제 #9
0
 private static IHttpAction GetExternalResourceAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
 {
     if (contextNode == null)
     {
         return factory.CreateDefaultAction(portalContext, contextNode, null);
         //return CreateApplication(actionContext, contextNode, null, new RewriteApp { TargetPath = actionContext.RequestedUrl });
     }
     return null;
 }
예제 #10
0
        private static IHttpAction GetSiteStartPageAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            if (contextNode == null)
                return null;
            if (!contextNode.GetNodeType().IsInstaceOfOrDerivedFrom("Site"))
                return null;
            //var startPage = portalContext.Site.StartPage;
            Page startPage = null;

            using (new SystemAccount())
            {
                var contextSite = Node.Load<Site>(contextNode.Id);
                if (contextSite != null && (portalContext.ActionName == null || portalContext.ActionName.ToLower() == "browse"))
                    startPage = contextSite.StartPage;
                if (startPage == null)
                    return null;
            }

            var relPath = startPage.Path.Replace(portalContext.Site.Path, "");
            return factory.CreateRedirectAction(portalContext, contextNode, null, relPath, false, true);
        }
예제 #11
0
        private static IHttpAction GetIIS5SVCRequestAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            // Rewrite path (create PathInfo) if service called on IIS5
            var httpContext = portalContext.OwnerHttpContext;
            const int XP_MAJOR_VERSION_NUMBER = 5;
            if (httpContext.Request.Path.Contains(".svc") && Environment.OSVersion.Version.Major == XP_MAJOR_VERSION_NUMBER)
            {
                string filePath, pathInfo, queryString;
                string originalPath = httpContext.Request.Path;

                string[] uriElements = System.Text.RegularExpressions.Regex.Split(originalPath, @".svc/");

                filePath = uriElements[0];
                if (!filePath.EndsWith(".svc", StringComparison.InvariantCultureIgnoreCase))
                    filePath = string.Concat(filePath, ".svc");

                pathInfo = uriElements.Length > 1 ? uriElements[1] : String.Empty;
                string qs = httpContext.Request.Url.Query;
                queryString = string.IsNullOrEmpty(qs) ? string.Empty : qs.Substring(1);

                httpContext.RewritePath(filePath, pathInfo, queryString);

                return factory.CreateRewriteAction(portalContext, contextNode, null, filePath, pathInfo, queryString);
            }
            return null;
        }
예제 #12
0
        private static IHttpAction GetFirstRunAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            //TODO: this is for WebPI first time execution, not really side by side friendly reconsideration needed.
            if (portalContext.Site == null)
            {
                Uri uri = portalContext.OwnerHttpContext.Request.Url;
                string uriPath = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
                string installTest = Path.Combine(uri.Authority, "/install/").ToLower();
                string lowerUrl = uri.ToString().ToLower();

                if (!lowerUrl.EndsWith("/default.aspx") &&
                    !lowerUrl.EndsWith("/config.aspx") &&
                    lowerUrl.IndexOf(installTest) < 0 &&
                    !uriPath.EndsWith(".axd"))
                {
                    var appName = HttpRuntime.AppDomainAppVirtualPath;
                    if (!appName.EndsWith("/"))
                        appName = appName + "/";

                    return factory.CreateRedirectAction(portalContext, contextNode, null, 
                        appName + "IISConfig/Config.aspx", false, false);
                }
            }
            return null;
        }
예제 #13
0
        internal static PortalContext Create(HttpContext context, PortalContextInitInfo initInfo)
        {
            PortalContext pc = new PortalContext();
            pc.Initialize(context, initInfo);

            context.Items.Add(CONTEXT_ITEM_KEY, pc);
            context.Items.Add(ApplicationStorage.DEVICEPARAMNAME, pc.DeviceName);

            return pc;
        }
예제 #14
0
        // ============================================================================================ Methods
        private static void SetThreadCulture(PortalContext portalContext)
        {
            // Set the CurrentCulture and the CurrentUICulture of the current thread based on the site language.
            // If the site language was set to "FallbackToDefault", or was set to an empty value, the thread culture
            // remain unmodified and will contain its default value (based on Web- and machine.config).
            var site = portalContext.Site;
            if (site != null)
            {
                bool cultureSet = false;
                if (site.EnableClientBasedCulture)
                {
                    // Set language to user's browser settings
                    var languages = HttpContext.Current.Request.UserLanguages;

                    string language = null;
                    if (languages != null && languages.Length > 0)
                        language = languages[0];

                    if (language != null)
                        language = language.ToLowerInvariant().Trim();

                    cultureSet = TrySetThreadCulture(language);
                }

                // culture is not yet resolved or resolution from client failed: use site language
                if (!cultureSet)
                    TrySetThreadCulture(site.Language);
            }
        }