当前位置: 首页>>代码示例>>C#>>正文


C# Node.First方法代码示例

本文整理汇总了C#中umbraco.NodeFactory.Node.First方法的典型用法代码示例。如果您正苦于以下问题:C# Node.First方法的具体用法?C# Node.First怎么用?C# Node.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在umbraco.NodeFactory.Node的用法示例。


在下文中一共展示了Node.First方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UrlTrackerDo

        static void UrlTrackerDo(string callingEventName, bool ignoreHttpStatusCode = false)
        {
            HttpContext context = HttpContext.Current;
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;

            if (!string.IsNullOrEmpty(request.QueryString[UrlTrackerSettings.HttpModuleCheck]))
            {
                response.Clear();
                response.Write(UrlTrackerSettings.HttpModuleCheck);
                response.StatusCode = 200;
                response.End();
                return;
            }

            LoggingHelper.LogInformation("UrlTracker HttpModule | {0} start", callingEventName);

            if (UrlTrackerSettings.IsDisabled)
            {
                LoggingHelper.LogInformation("UrlTracker HttpModule | UrlTracker is disabled by config");
                return;
            }

            string url = request.RawUrl;
            if (url.StartsWith("/"))
                url = url.Substring(1);

            LoggingHelper.LogInformation("UrlTracker HttpModule | Incoming URL is: {0}", url);

            if (_urlTrackerInstalled && (response.StatusCode == (int)HttpStatusCode.NotFound || ignoreHttpStatusCode))
            {
                if (response.StatusCode == (int)HttpStatusCode.NotFound)
                    LoggingHelper.LogInformation("UrlTracker HttpModule | Response statusCode is 404, continue URL matching");
                else
                    LoggingHelper.LogInformation("UrlTracker HttpModule | Checking for forced redirects (AcquireRequestState), continue URL matching");

                string urlWithoutQueryString = url;
                if (InfoCaster.Umbraco.UrlTracker.Helpers.UmbracoHelper.IsReservedPathOrUrl(url))
                {
                    LoggingHelper.LogInformation("UrlTracker HttpModule | URL is an umbraco reserved path or url, ignore request");
                    return;
                }

                bool urlHasQueryString = request.QueryString.HasKeys() && url.Contains('?');
                if (urlHasQueryString)
                    urlWithoutQueryString = url.Substring(0, url.IndexOf('?'));

                string shortestUrl = UrlTrackerHelper.ResolveShortestUrl(urlWithoutQueryString);

                int rootNodeId = -1;
                List<UrlTrackerDomain> domains = UmbracoHelper.GetDomains();
                if (domains.Any())
                {
                    string fullRawUrl;
                    string previousFullRawUrlTest;
                    string fullRawUrlTest;
                    fullRawUrl = previousFullRawUrlTest = fullRawUrlTest = string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Host, request.RawUrl);

                    UrlTrackerDomain urlTrackerDomain;
                    do
                    {
                        if (previousFullRawUrlTest.EndsWith("/"))
                        {
                            urlTrackerDomain = domains.FirstOrDefault(x => x.UrlWithDomain == fullRawUrlTest);
                            if (urlTrackerDomain != null)
                            {
                                rootNodeId = urlTrackerDomain.NodeId;
                                urlWithoutQueryString = fullRawUrl.Replace(fullRawUrlTest, string.Empty);
                                if (urlWithoutQueryString.StartsWith("/"))
                                    urlWithoutQueryString = urlWithoutQueryString.Substring(1);
                                break;
                            }
                        }
                        previousFullRawUrlTest = fullRawUrlTest;
                        fullRawUrlTest = fullRawUrlTest.Substring(0, fullRawUrlTest.Length - 1);
                    }
                    while (fullRawUrlTest.Length > 0);
                }
                if (rootNodeId == -1)
                {
                    rootNodeId = -1;
                    List<INode> children = new Node(rootNodeId).ChildrenAsList;
                    if (children != null && children.Any())
                        rootNodeId = children.First().Id;
                }
                LoggingHelper.LogInformation("UrlTracker HttpModule | Current request's rootNodeId: {0}", rootNodeId);

                string redirectUrl = null;
                int? redirectHttpCode = null;
                bool redirectPassThroughQueryString = true;

                if (!ignoreHttpStatusCode)
                {
                    // Normal matching (database)
                    LoadUrlTrackerMatchesFromDatabase(request, urlWithoutQueryString, urlHasQueryString, shortestUrl, rootNodeId, ref redirectUrl, ref redirectHttpCode, ref redirectPassThroughQueryString);
                }
                else
                {
                    // Forced matching (cache)
                    LoadUrlTrackerMatchesFromCache(request, urlWithoutQueryString, urlHasQueryString, shortestUrl, rootNodeId, ref redirectUrl, ref redirectHttpCode, ref redirectPassThroughQueryString);
//.........这里部分代码省略.........
开发者ID:JimBobSquarePants,项目名称:UrlTracker,代码行数:101,代码来源:UrlTrackerModule.cs

示例2: context_EndRequest

        void context_EndRequest(object sender, EventArgs e)
        {
            HttpContext context = HttpContext.Current;
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;

            if (!string.IsNullOrEmpty(request.QueryString[UrlTrackerSettings.HttpModuleCheck]))
            {
                response.Clear();
                response.Write(UrlTrackerSettings.HttpModuleCheck);
                response.StatusCode = 200;
                response.End();
                return;
            }

            UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | PostReleaseRequestState start");

            if (UrlTrackerSettings.IsDisabled)
            {
                UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | UrlTracker is disabled by config");
                return;
            }

            string url = request.RawUrl;
            if (url.StartsWith("/"))
                url = url.Substring(1);

            UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | Incoming URL is: {0}", url);

            if (response.StatusCode == 404)
            {
                UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | Response statusCode is 404, continue URL matching");

                string urlWithoutQueryString = url;
                if (InfoCaster.Umbraco.UrlTracker.Helpers.UmbracoHelper.IsReservedPathOrUrl(url))
                {
                    UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | URL is an umbraco reserved path or url, ignore request");
                    return;
                }

                bool urlHasQueryString = request.QueryString.HasKeys() && url.Contains('?');
                if (urlHasQueryString)
                    urlWithoutQueryString = url.Substring(0, url.IndexOf('?'));

                string shortestUrl = UrlTrackerHelper.ResolveShortestUrl(urlWithoutQueryString);

                string host = request.Url.Host;

                int rootNodeId = Domain.GetRootFromDomain(host);
                if (rootNodeId == -1)
                {
                    rootNodeId = -1;
                    List<INode> children = new Node(rootNodeId).ChildrenAsList;
                    if (children != null && children.Any())
                        rootNodeId = children.First().Id;

                }
                UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | Current request's rootNodeId: {0}", rootNodeId);

                string redirectUrl = null;
                int? redirectHttpCode = null;
                bool redirectPassThroughQueryString = true;

                // Normal matching
                string query = "SELECT * FROM icUrlTracker WHERE Is404 = 0 AND (RedirectRootNodeId = @redirectRootNodeId OR RedirectRootNodeId IS NULL) AND (OldUrl = @url OR OldUrl = @shortestUrl) ORDER BY OldUrlQueryString DESC";
                using (IRecordsReader reader = _sqlHelper.ExecuteReader(query, _sqlHelper.CreateParameter("redirectRootNodeId", rootNodeId), _sqlHelper.CreateParameter("url", urlWithoutQueryString), _sqlHelper.CreateParameter("shortestUrl", shortestUrl)))
                {
                    while (reader.Read())
                    {
                        UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | URL match found");
                        if (!reader.IsNull("RedirectNodeId"))
                        {
                            int redirectNodeId = reader.GetInt("RedirectNodeId");
                            UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | Redirect node id: {0}", redirectNodeId);
                            Node n = new Node(redirectNodeId);
                            if (n != null && n.Name != null && n.Id > 0)
                            {
                                redirectUrl = umbraco.library.NiceUrl(redirectNodeId).StartsWith("http") ? umbraco.library.NiceUrl(redirectNodeId) : string.Format("{0}://{1}{2}{3}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port != 80 ? string.Concat(":", HttpContext.Current.Request.Url.Port) : string.Empty, umbraco.library.NiceUrl(redirectNodeId));
                                if (redirectUrl.StartsWith("http"))
                                {
                                    Uri redirectUri = new Uri(redirectUrl);
                                    redirectUrl = redirectUri.PathAndQuery.StartsWith("/") && redirectUri.PathAndQuery != "/" ? redirectUri.PathAndQuery.Substring(1) : redirectUri.PathAndQuery;
                                }
                                UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | Redirect url set to: {0}", redirectUrl);
                            }
                            else
                                UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | Redirect node is invalid; node is null, name is null or id <= 0");
                        }
                        else if (!reader.IsNull("RedirectUrl"))
                        {
                            redirectUrl = reader.GetString("RedirectUrl");
                            UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | Redirect url set to: {0}", redirectUrl);
                        }

                        redirectPassThroughQueryString = reader.GetBoolean("RedirectPassThroughQueryString");
                        UrlTrackerLoggingHelper.LogInformation("UrlTracker HttpModule | PassThroughQueryString is {0}", redirectPassThroughQueryString ? "enabled" : "disabled");

                        NameValueCollection oldUrlQueryString = null;
                        if (!reader.IsNull("OldUrlQueryString"))
                        {
//.........这里部分代码省略.........
开发者ID:neehouse,项目名称:UrlTracker,代码行数:101,代码来源:UrlTrackerModule.cs


注:本文中的umbraco.NodeFactory.Node.First方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。