コード例 #1
0
        public void Application_Error_WhenDangerousRequest_PageRedirected()
        {
            // Arrange
            var exp = new Exception("A potentially dangerous Request");

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.InvalidLink.ToString()),
                () => RedirectUrl.ShouldContain(SampleHostPath));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp),
                () => _logDictionary[exp].ShouldContain($"CustomerID: {1}"),
                () => _logDictionary[exp].ShouldContain($"TestUser"));
        }
コード例 #2
0
        public void Application_Error_WhenHttpExceptionBaseExceptionOtherException_PageRedirected()
        {
            // Arrange
            var exp = new Exception(TestDemoException, new TestHelperException <Exception>());

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString()));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp.InnerException));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp.InnerException),
                () => _logDictionary[exp.InnerException].ShouldContain(SampleHost),
                () => _logDictionary[exp.InnerException].ShouldContain(SampleHostPath));
        }
コード例 #3
0
        public void Application_Error_InnerExceptionECNException_PageRedirected()
        {
            // Arrange
            var exp = new ECNException(new List <ECNError>
            {
                new ECNError
                {
                    ErrorMessage = TestErrorMessage,
                    Entity       = Entity.Blast,
                    Method       = Method.Get
                }
            });

            SetUpFakes();
            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.ValidationError.ToString()));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp),
                () => _logDictionary[exp].ShouldContain(TestErrorMessage),
                () => _logDictionary[exp].ShouldContain(Entity.Blast.ToString()),
                () => _logDictionary[exp].ShouldContain(Method.Get.ToString()));
        }
コード例 #4
0
ファイル: ErrorPage.cs プロジェクト: REHERC/Distance-Toolbox
        public ErrorPage(string Title_, string Message_, PageRedirect Redirect_ = null)
        {
            InitializeComponent();

            this.ErrorHeader.Text = Title_;
            this.ErrorMessageContainer.Visible = (bool)(Message_.Length > 0);
            this.ErrorMessage.Text             = Message_;

            Redirect = Redirect_;

            FinalizeComponent();
        }
コード例 #5
0
        public void Application_Error_InnerExceptionSecurityError_PageRedirected()
        {
            // Arrange
            ShimHttpServerUtility.AllInstances.GetLastError = (u) => new Exception("dummy exception", new SecurityException());

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.SecurityError.ToString());
        }
コード例 #6
0
        public void Application_Error_InnerExceptionSecurityErrorAndSecurityTypeFeatureNotEnabled_PageRedirected()
        {
            // Arrange
            ShimHttpServerUtility.AllInstances.GetLastError = (u) => new Exception(
                TestDemoException,
                new SecurityException
            {
                SecurityType = SecurityExceptionType.FeatureNotEnabled
            });

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain("/main/featureAccessError.aspx"));
        }
コード例 #7
0
        public void Application_Error_WhenHttpExceptionBaseExceptionHttpException_PageRedirected()
        {
            // Arrange
            var exp = new TestHelperException <HttpException>();

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.InvalidLink.ToString());
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldBeEmpty();
        }
コード例 #8
0
        public void Application_Error_WhenGeneralAspNetException_PageRedirected()
        {
            // Arrange
            var exp = new Exception("ASP.NET session has expired or could not be found");

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString());
            RedirectUrl.ShouldContain(SampleHostPath);
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldBeEmpty();
        }
コード例 #9
0
        public void Application_Error_InnerExceptionViewStateException_PageRedirected()
        {
            // Arrange
            var exp = new Exception("demo exception", new ViewStateException());

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.Timeout.ToString());
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldNotBeEmpty();
            _logDictionary.ShouldContainKey(exp);
            _logDictionary[exp].ShouldContain(SampleUserAgent);
        }
コード例 #10
0
        public void Application_Error_WhenGeneralException_PageRedirected()
        {
            // Arrange
            var exp = new Exception("does not exist");

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString()),
                () => RedirectUrl.ShouldContain("/error.aspx?"),
                () => RedirectUrl.ShouldContain(SampleHostPath));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldBeEmpty();
        }
コード例 #11
0
        public void Application_Error_WhenUserCurrentSessionException_PageRedirected()
        {
            // Arrange
            var exp = new Exception();

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString());
            RedirectUrl.ShouldContain(SampleHostPath);
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldNotBeEmpty();
            _logDictionary.ShouldContainKey(exp);
            _logDictionary[exp].ShouldContain($"CustomerID: {1}");
            _logDictionary[exp].ShouldContain($"TestUser");
        }
コード例 #12
0
        public void Application_Error_WhenTransactionAbortedException_PageRedirected()
        {
            // Arrange
            var exp = new Exception(TestDemoException, new TransactionAbortedException());

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.Timeout.ToString()));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp),
                () => _logDictionary[exp].ShouldContain(SampleUserAgent));
        }
コード例 #13
0
ファイル: NodeTreeItem.cs プロジェクト: zhongqi013/cms
        public string GetItemHtml(ELoadingType loadingType, string returnUrl, NameValueCollection additional)
        {
            var htmlBuilder  = new StringBuilder();
            var parentsCount = _nodeInfo.ParentsCount;

            for (var i = 0; i < parentsCount; i++)
            {
                htmlBuilder.Append($@"<img align=""absmiddle"" src=""{_iconEmptyUrl}"" />");
            }

            if (_nodeInfo.ChildrenCount > 0)
            {
                htmlBuilder.Append(
                    _nodeInfo.SiteId == _nodeInfo.Id
                        ? $@"<img align=""absmiddle"" style=""cursor:pointer"" onClick=""displayChildren(this);"" isAjax=""false"" isOpen=""true"" id=""{_nodeInfo
                            .Id}"" src=""{_iconMinusUrl}"" />"
                        : $@"<img align=""absmiddle"" style=""cursor:pointer"" onClick=""displayChildren(this);"" isAjax=""true"" isOpen=""false"" id=""{_nodeInfo
                            .Id}"" src=""{_iconPlusUrl}"" />");
            }
            else
            {
                htmlBuilder.Append($@"<img align=""absmiddle"" src=""{_iconEmptyUrl}"" />");
            }

            if (!string.IsNullOrEmpty(_iconFolderUrl))
            {
                htmlBuilder.Append(
                    _nodeInfo.Id > 0
                        ? $@"<a href=""{PageRedirect.GetRedirectUrlToChannel(_nodeInfo.SiteId, _nodeInfo.Id)}"" target=""_blank"" title=""浏览页面""><img align=""absmiddle"" border=""0"" src=""{_iconFolderUrl}"" style=""max-height: 22px; max-width: 22px"" /></a>"
                        : $@"<img align=""absmiddle"" src=""{_iconFolderUrl}"" style=""max-height: 22px; max-width: 22px"" />");
            }

            htmlBuilder.Append("&nbsp;");

            if (_enabled)
            {
                if (loadingType == ELoadingType.ContentTree)
                {
                    var linkUrl = PageContent.GetRedirectUrl(_nodeInfo.SiteId, _nodeInfo.Id);

                    htmlBuilder.Append(
                        $"<a href='{linkUrl}' isLink='true' onclick='fontWeightLink(this)' target='content'>{_nodeInfo.ChannelName}</a>");
                }
                else if (loadingType == ELoadingType.ChannelSelect)
                {
                    var linkUrl = ModalChannelSelect.GetRedirectUrl(_nodeInfo.SiteId, _nodeInfo.Id);
                    if (additional != null)
                    {
                        if (!string.IsNullOrEmpty(additional["linkUrl"]))
                        {
                            linkUrl = additional["linkUrl"] + _nodeInfo.Id;
                        }
                        else
                        {
                            foreach (string key in additional.Keys)
                            {
                                linkUrl += $"&{key}={additional[key]}";
                            }
                        }
                    }
                    htmlBuilder.Append($"<a href='{linkUrl}'>{_nodeInfo.ChannelName}</a>");
                }
                else
                {
                    if (AdminUtility.HasChannelPermissions(_administratorName, _nodeInfo.SiteId, _nodeInfo.Id, ConfigManager.Permissions.Channel.ChannelEdit))
                    {
                        var onClickUrl = ModalChannelEdit.GetOpenWindowString(_nodeInfo.SiteId, _nodeInfo.Id, returnUrl);
                        htmlBuilder.Append(
                            $@"<a href=""javascript:;;"" onClick=""{onClickUrl}"" title=""快速编辑栏目"">{_nodeInfo.ChannelName}</a>");
                    }
                    else
                    {
                        htmlBuilder.Append($@"<a href=""javascript:;;"">{_nodeInfo.ChannelName}</a>");
                    }
                }
            }
            else
            {
                htmlBuilder.Append(_nodeInfo.ChannelName);
            }

            if (_nodeInfo.SiteId != 0)
            {
                htmlBuilder.Append("&nbsp;");

                htmlBuilder.Append(ChannelManager.GetNodeTreeLastImageHtml(_siteInfo, _nodeInfo));

                if (_nodeInfo.ContentNum < 0)
                {
                    return(htmlBuilder.ToString());
                }

                htmlBuilder.Append(
                    $@"<span style=""font-size:8pt;font-family:arial"" class=""gray"">({_nodeInfo.ContentNum})</span>");
            }

            return(htmlBuilder.ToString());
        }
コード例 #14
0
        public string GetItemHtml(ELoadingType loadingType, string returnUrl, NameValueCollection additional)
        {
            var htmlBuilder  = new StringBuilder();
            var parentsCount = _channelInfo.ParentsCount;

            for (var i = 0; i < parentsCount; i++)
            {
                htmlBuilder.Append($@"<img align=""absmiddle"" src=""{_iconEmptyUrl}"" />");
            }

            if (_channelInfo.ChildrenCount > 0)
            {
                htmlBuilder.Append(
                    _channelInfo.SiteId == _channelInfo.Id
                        ? $@"<img align=""absmiddle"" style=""cursor:pointer; margin-top: -5px; margin-right: 2px;"" onClick=""event.stopPropagation();displayChildren(this);"" isAjax=""false"" isOpen=""true"" id=""{_channelInfo
                            .Id}"" src=""{_iconMinusUrl}"" />"
                        : $@"<img align=""absmiddle"" style=""cursor:pointer; margin-top: -5px; margin-right: 2px;"" onClick=""event.stopPropagation();displayChildren(this);"" isAjax=""true"" isOpen=""false"" id=""{_channelInfo
                            .Id}"" src=""{_iconPlusUrl}"" />");
            }
            else
            {
                htmlBuilder.Append($@"<img align=""absmiddle"" src=""{_iconEmptyUrl}"" />");
            }

            var contentModelIconHtml = $@"<i class=""{_contentModelIconClass}""></i>";

            if (_channelInfo.Id > 0)
            {
                contentModelIconHtml = $@"<a href=""{PageRedirect.GetRedirectUrlToChannel(_channelInfo.SiteId, _channelInfo.Id)}"" target=""_blank"" title=""浏览页面"" onclick=""event.stopPropagation()"">{contentModelIconHtml}</a>";
            }

            htmlBuilder.Append(contentModelIconHtml);
            htmlBuilder.Append("&nbsp;");

            if (_enabled)
            {
                if (loadingType == ELoadingType.ContentTree)
                {
                    var linkUrl = PageContent.GetRedirectUrl(_channelInfo.SiteId, _channelInfo.Id);
                    if (!string.IsNullOrEmpty(additional?["linkUrl"]))
                    {
                        linkUrl = PageUtils.AddQueryStringIfNotExists(additional["linkUrl"], new NameValueCollection
                        {
                            ["channelId"] = _channelInfo.Id.ToString()
                        });
                    }

                    linkUrl = PageUtils.GetLoadingUrl(linkUrl);

                    htmlBuilder.Append(
                        $"<a href='{linkUrl}' isLink='true' onclick='fontWeightLink(this)' target='content'>{_channelInfo.ChannelName}</a>");
                }
                else if (loadingType == ELoadingType.ChannelSelect)
                {
                    var linkUrl = ModalChannelSelect.GetRedirectUrl(_channelInfo.SiteId, _channelInfo.Id);
                    if (additional != null)
                    {
                        if (!string.IsNullOrEmpty(additional["linkUrl"]))
                        {
                            linkUrl = additional["linkUrl"] + _channelInfo.Id;
                        }
                        else
                        {
                            foreach (string key in additional.Keys)
                            {
                                linkUrl += $"&{key}={additional[key]}";
                            }
                        }
                    }
                    htmlBuilder.Append($"<a href='{linkUrl}'>{_channelInfo.ChannelName}</a>");
                }
                else
                {
                    if (_permissionManager.HasChannelPermissions(_channelInfo.SiteId, _channelInfo.Id, ConfigManager.ChannelPermissions.ChannelEdit))
                    {
                        var onClickUrl = ModalChannelEdit.GetOpenWindowString(_channelInfo.SiteId, _channelInfo.Id, returnUrl);
                        htmlBuilder.Append(
                            $@"<a href=""javascript:;;"" onClick=""{onClickUrl}"" title=""快速编辑栏目"">{_channelInfo.ChannelName}</a>");
                    }
                    else
                    {
                        htmlBuilder.Append($@"<a href=""javascript:;"">{_channelInfo.ChannelName}</a>");
                    }
                }
            }
            else
            {
                htmlBuilder.Append($"<span>{_channelInfo.ChannelName}</span>");
            }

            if (_channelInfo.SiteId != 0)
            {
                htmlBuilder.Append("&nbsp;");

                htmlBuilder.Append(ChannelManager.GetNodeTreeLastImageHtml(_siteInfo, _channelInfo));

                if (_channelInfo.ContentNum < 0)
                {
                    return(htmlBuilder.ToString());
                }

                htmlBuilder.Append(
                    $@"<span style=""font-size:8pt;font-family:arial"" class=""gray"">({_channelInfo.ContentNum})</span>");
            }

            return(htmlBuilder.ToString());
        }
コード例 #15
0
        public string GetItemHtml(int parentContentNum)
        {
            var htmlBuilder = new StringBuilder();

            for (var i = 0; i < _parentsCount; i++)
            {
                htmlBuilder.Append($"<img align=\"absmiddle\" src=\"{_iconEmptyUrl}\"/>");
            }

            if (_isDisplay)
            {
                if (_hasChildren)
                {
                    if (_selected)
                    {
                        htmlBuilder.Append(
                            $"<img align=\"absmiddle\" style=\"cursor:pointer;\" onClick=\"displayChildren(this);\" isOpen=\"true\" src=\"{_iconMinusUrl}\"/>");
                    }
                    else
                    {
                        htmlBuilder.Append(
                            $"<img align=\"absmiddle\" style=\"cursor:pointer;\" onClick=\"displayChildren(this);\" isOpen=\"false\" src=\"{_iconPlusUrl}\"/>");
                    }
                }
                else
                {
                    htmlBuilder.Append($"<img align=\"absmiddle\" src=\"{_iconEmptyUrl}\"/>");
                }
            }
            else
            {
                if (_hasChildren)
                {
                    htmlBuilder.Append(
                        $"<img align=\"absmiddle\" style=\"cursor:pointer;\" onClick=\"displayChildren(this);\" isOpen=\"false\" src=\"{_iconPlusUrl}\"/>");
                }
                else
                {
                    htmlBuilder.Append($"<img align=\"absmiddle\" src=\"{_iconEmptyUrl}\"/>");
                }
            }

            if (!string.IsNullOrEmpty(_iconFolderUrl))
            {
                if (_channelId > 0)
                {
                    htmlBuilder.Append(
                        $"<a href=\"{PageRedirect.GetRedirectUrlToChannel(_siteId, _channelId)}\" target=\"_blank\" title='浏览页面'><img align=\"absmiddle\" border=\"0\" src=\"{_iconFolderUrl}\"/></a>");
                }
                else
                {
                    htmlBuilder.Append($"<img align=\"absmiddle\" src=\"{_iconFolderUrl}\"/>");
                }
            }

            htmlBuilder.Append("&nbsp;");

            if (_enabled)
            {
                if (!string.IsNullOrEmpty(_linkUrl))
                {
                    var targetHtml      = (string.IsNullOrEmpty(_target)) ? string.Empty : $"target='{_target}'";
                    var clickChangeHtml = (_isClickChange) ? "onclick='openFolderByA(this);'" : string.Empty;

                    htmlBuilder.Append(
                        $"<a href='{_linkUrl}' {targetHtml} {clickChangeHtml} isTreeLink='true'>{_text}</a>");
                }
                else if (!string.IsNullOrEmpty(_onClickUrl))
                {
                    htmlBuilder.Append(
                        $@"<a href=""javascript:;"" onClick=""{_onClickUrl}"" title='快速编辑栏目' isTreeLink='true'>{_text}</a>");
                }
                else
                {
                    htmlBuilder.Append(_text);
                }
            }
            else
            {
                htmlBuilder.Append(_text);
            }

            if (_isNodeTree && _siteId != 0)
            {
                var siteInfo = SiteManager.GetSiteInfo(_siteId);

                htmlBuilder.Append("&nbsp;");
                htmlBuilder.Append(ChannelManager.GetNodeTreeLastImageHtml(siteInfo, ChannelManager.GetChannelInfo(_siteId, _channelId)));

                if (_contentNum >= 0)
                {
                    htmlBuilder.Append("&nbsp;");
                    htmlBuilder.Append(
                        $"<span style=\"font-size:8pt;font-family:arial\" class=\"gray\">(总共:{parentContentNum},本级:{_contentNum})</span>");
                }
            }

            return(htmlBuilder.ToString());
        }
コード例 #16
0
ファイル: WebUtils.cs プロジェクト: zhongqi013/cms
        public static string GetContentTitle(SiteInfo siteInfo, ContentInfo contentInfo, string pageUrl)
        {
            string url;
            var    title = ContentUtility.FormatTitle(contentInfo.GetString(BackgroundContentAttribute.TitleFormatString), contentInfo.Title);

            var displayString = contentInfo.IsTop ? $"<span style='color:#ff0000;text-decoration:none' title='醒目'>{title}</span>" : title;

            if (contentInfo.ChannelId < 0)
            {
                url = displayString;
            }
            else if (contentInfo.IsChecked)
            {
                url =
                    $"<a href='{PageRedirect.GetRedirectUrlToContent(siteInfo.Id, contentInfo.ChannelId, contentInfo.Id)}' target='blank'>{displayString}</a>";
            }
            else
            {
                url =
                    $"<a href='{PageContentView.GetContentViewUrl(siteInfo.Id, contentInfo.ChannelId, contentInfo.Id, pageUrl)}'>{displayString}</a>";
            }

            var image = string.Empty;

            if (contentInfo.IsRecommend)
            {
                image += "&nbsp;<img src='../pic/icon/recommend.gif' title='推荐' align='absmiddle' border=0 />";
            }
            if (contentInfo.IsHot)
            {
                image += "&nbsp;<img src='../pic/icon/hot.gif' title='热点' align='absmiddle' border=0 />";
            }
            if (contentInfo.IsTop)
            {
                image += "&nbsp;<img src='../pic/icon/top.gif' title='置顶' align='absmiddle' border=0 />";
            }
            if (contentInfo.ReferenceId > 0)
            {
                if (contentInfo.GetString(ContentAttribute.TranslateContentType) == ETranslateContentType.ReferenceContent.ToString())
                {
                    image += "&nbsp;<img src='../pic/icon/reference.png' title='引用内容' align='absmiddle' border=0 />(引用内容)";
                }
                else if (contentInfo.GetString(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString())
                {
                    image += "&nbsp;<img src='../pic/icon/reference.png' title='引用地址' align='absmiddle' border=0 />(引用地址)";
                }
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(ContentAttribute.LinkUrl)))
            {
                image += "&nbsp;<img src='../pic/icon/link.png' title='外部链接' align='absmiddle' border=0 />";
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.ImageUrl)))
            {
                var imageUrl         = PageUtility.ParseNavigationUrl(siteInfo, contentInfo.GetString(BackgroundContentAttribute.ImageUrl), true);
                var openWindowString = ModalMessage.GetOpenWindowString(siteInfo.Id, "预览图片", $"<img src='{imageUrl}' />", 500, 500);
                image +=
                    $@"&nbsp;<a href=""javascript:;"" onclick=""{openWindowString}""><img src='../assets/icons/img.gif' title='预览图片' align='absmiddle' border=0 /></a>";
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.VideoUrl)))
            {
                var openWindowString = ModalMessage.GetOpenWindowStringToPreviewVideoByUrl(siteInfo.Id, contentInfo.GetString(BackgroundContentAttribute.VideoUrl));
                image +=
                    $@"&nbsp;<a href=""javascript:;"" onclick=""{openWindowString}""><img src='../pic/icon/video.png' title='预览视频' align='absmiddle' border=0 /></a>";
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.FileUrl)))
            {
                image += "&nbsp;<img src='../pic/icon/attachment.gif' title='附件' align='absmiddle' border=0 />";
                if (siteInfo.Additional.IsCountDownload)
                {
                    var count = CountManager.GetCount(siteInfo.TableName, contentInfo.Id.ToString(), ECountType.Download);
                    image += $"下载次数:<strong>{count}</strong>";
                }
            }
            if (!string.IsNullOrEmpty(contentInfo.WritingUserName))
            {
                var openWindowString = ModalUserView.GetOpenWindowString(contentInfo.WritingUserName);
                image +=
                    $@"&nbsp;(<a href=""javascript:;"" onclick=""{openWindowString}"">投稿用户:{contentInfo.WritingUserName}</a>)";
            }
            return(url + image);
        }
コード例 #17
0
ファイル: WebUtils.cs プロジェクト: xueyu19870128/MyProject
        public static string GetContentTitle(SiteInfo siteInfo, ContentInfo contentInfo, string pageUrl)
        {
            string url;
            var    title = ContentUtility.FormatTitle(contentInfo.GetString(ContentAttribute.GetFormatStringAttributeName(ContentAttribute.Title)), contentInfo.Title);

            var displayString = contentInfo.IsColor ? $"<span style='color:#ff0000;text-decoration:none' title='醒目'>{title}</span>" : title;

            if (contentInfo.IsChecked && contentInfo.ChannelId > 0)
            {
                url =
                    $"<a href='{PageRedirect.GetRedirectUrlToContent(siteInfo.Id, contentInfo.ChannelId, contentInfo.Id)}' target='blank'>{displayString}</a>";
            }
            else
            {
                var layerUrl =
                    $@"contentsLayerView.cshtml?siteId={siteInfo.Id}&channelId={-contentInfo.ChannelId}&contentId={contentInfo.Id}";
                //ModalContentView.GetOpenWindowString(siteInfo.Id, contentInfo.ChannelId, contentInfo.Id, pageUrl)
                url =
                    $@"<a href=""javascript:;"" onclick=""{LayerUtils.GetOpenScript2("查看内容", layerUrl)}"">{displayString}</a>";
            }

            var image = string.Empty;

            if (contentInfo.IsRecommend)
            {
                image += "&nbsp;<img src='../pic/icon/recommend.gif' title='推荐' align='absmiddle' border=0 />";
            }
            if (contentInfo.IsHot)
            {
                image += "&nbsp;<img src='../pic/icon/hot.gif' title='热点' align='absmiddle' border=0 />";
            }
            if (contentInfo.IsTop)
            {
                image += "&nbsp;<img src='../pic/icon/top.gif' title='置顶' align='absmiddle' border=0 />";
            }
            if (contentInfo.ReferenceId > 0)
            {
                if (contentInfo.GetString(ContentAttribute.TranslateContentType) == ETranslateContentType.ReferenceContent.ToString())
                {
                    image += "&nbsp;<img src='../pic/icon/reference.png' title='引用内容' align='absmiddle' border=0 />(引用内容)";
                }
                else if (contentInfo.GetString(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString())
                {
                    image += "&nbsp;<img src='../pic/icon/reference.png' title='引用地址' align='absmiddle' border=0 />(引用地址)";
                }
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(ContentAttribute.LinkUrl)))
            {
                image += "&nbsp;<img src='../pic/icon/link.png' title='外部链接' align='absmiddle' border=0 />";
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.ImageUrl)))
            {
                var imageUrl         = PageUtility.ParseNavigationUrl(siteInfo, contentInfo.GetString(BackgroundContentAttribute.ImageUrl), true);
                var openWindowString = ModalMessage.GetOpenWindowString(siteInfo.Id, "预览图片", $"<img src='{imageUrl}' />", 500, 500);
                image +=
                    $@"&nbsp;<a href=""javascript:;"" onclick=""{openWindowString}""><img src='../assets/icons/img.gif' title='预览图片' align='absmiddle' border=0 /></a>";
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.VideoUrl)))
            {
                var openWindowString = ModalMessage.GetOpenWindowStringToPreviewVideoByUrl(siteInfo.Id, contentInfo.GetString(BackgroundContentAttribute.VideoUrl));
                image +=
                    $@"&nbsp;<a href=""javascript:;"" onclick=""{openWindowString}""><img src='../pic/icon/video.png' title='预览视频' align='absmiddle' border=0 /></a>";
            }
            if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.FileUrl)))
            {
                image += "&nbsp;<img src='../pic/icon/attachment.gif' title='附件' align='absmiddle' border=0 />";
            }
            return(url + image);
        }