' /'中的服务器错误应用程序从sitecore的下拉列表中选择任何国家/地区列表

时间:2015-05-13 09:17:35

标签: asp.net validation sitecore

我已成功使用sitecore中的重定向将我的一个页面重定向到404错误页面。问题是当我从下拉列表中选择任何国家时,我得到以下错误:

  

"无效的回发或回调参数。使用配置或<%@ Page EnableEventValidation =" true"启用事件验证。 %GT;在页面中。
  出于安全考虑,此功能会验证回发或回调事件的参数是否来自最初呈现它们的服务器控件   如果数据有效且符合预期,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证。"

我不想通过设置'enableEventValidation = false'来妥协安全性。通过这样做它的工作正常,但我需要一些替代解决方案。而且,是的,我的下拉式绑定也在!postback内。

甚至我尝试按照博客中的建议注册ClientScriptManager.RegisterForEventValidation方法,但它没有用。

404页面的一些代码部分是:

using System;

using Business;

using Sitecore.Data.Items;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Sitecore.Web.UI.WebControls;
using System.Collections.Generic;
using System.Linq;
using Sitecore.Diagnostics;
using System.Web;
using Sitecore.Data.Fields;

/// <summary>
/// title link list control
/// </summary>
public partial class ErrorPage_Link_List : System.Web.UI.UserControl
{
    int counter = 0;

    /// <summary>
    /// Gets the datasource item.
    /// </summary>
    /// <value>
    /// The datasource item.
    /// </value>
    internal Item DatasourceItem
    {
        get { return this.GetDataSourceItem(); }
    }

    /// <summary>
    /// Gets the title.
    /// </summary>
    /// <value>
    /// The title.
    /// </value>
    protected string Title
    {
        get { return DatasourceItem.Name; }
    }

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        base.Render(writer);

        // Apply Response Headers  
        HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        HttpContext.Current.Response.StatusCode = 404;
        HttpContext.Current.Response.StatusDescription = "404 Not Found";
        HttpContext.Current.Response.End();
    }

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    private void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //gets the items that has the Checkbox "Show In Sitemap" Checked from, current item datasource
            //and innovative aproach and about avanade
            var source = DatasourceItem.Children.Where(c => c["Show in SiteMap"] == "1").ToList();

            Item innovApproach = Sitecore.Context.Database.GetItem(Constants.ItemsID.InnovativeApproach);
            foreach (Item item1 in innovApproach.Children.Where(c => c["Show in SiteMap"] == "1"))
            {
                source.Add(item1);
            }



            source.Add(Sitecore.Context.Database.GetItem(Constants.ItemsID.CustomerResults));

            Item servAndSol = Sitecore.Context.Database.GetItem(Constants.ItemsID.AboutAvanade);
            foreach (Item item in servAndSol.Children.Where(c => c["Show in SiteMap"] == "1"))
            {
                source.Add(item);
            }



            rptSection.DataSource = source;
            rptSection.DataBind();
        }
        catch (Exception ex)
        {
            Log.Error(string.Format("ErrorPage_Link_List.PageLoad() - {0}", ex.Message), ex, ex.TargetSite);
        }
    }

    /// <summary>
    /// Working with sections
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptSection_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {

            //Finding item title, rptLinkItem repeater and the actual item to work with.
            HtmlGenericControl clearDiv = e.Item.FindControl("clearDiv") as HtmlGenericControl;
            HtmlGenericControl itemTitle = e.Item.FindControl("title") as HtmlGenericControl;
            HtmlGenericControl subtitle = e.Item.FindControl("subtitle") as HtmlGenericControl;
            Repeater rptLinkItem = e.Item.FindControl("rptLinkItem") as Repeater;
            Item srcItem = (Item)e.Item.DataItem;
            IEnumerable<Item> dataSource = null;
            if (srcItem.ID.ToString().Equals(Constants.ItemsID.Careers2))
                dataSource = ((Sitecore.Data.Fields.MultilistField)srcItem.Fields[Constants.Fields.SiteMap]).GetItems().ToList();
            else
                dataSource = SitecoreExtensions.GetItemsFromCustomMultiList(srcItem, Constants.Fields.SiteMap).Where(c => c.IsActive()).ToList();
            if (dataSource.Count() > 0)
            {
                if (!string.IsNullOrEmpty(srcItem[Constants.Fields.SectionName]))
                {
                    itemTitle.InnerHtml = srcItem[Constants.Fields.SectionName];
                }
                else
                {
                    itemTitle.InnerHtml = srcItem[Constants.Fields.Title];
                }


                //Bind the rptLinkItem repeater with the item children that are active
                rptLinkItem.DataSource = dataSource;
                rptLinkItem.DataBind();

                counter++;
                if (counter == 4)
                {
                    clearDiv.Attributes.Add("class", "clearBoth");
                    counter = 0;
                }


            }

        }
        catch (Exception ex)
        {
            Log.Error(string.Format("ErrorPage_Link_List.rptSection_ItemDataBound() - {0}", ex.Message), ex, ex.TargetSite);
        }
    }


    /// <summary>
    /// Working with link items
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptLinkItem_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            //Finding item title and the actual item to work with.
            HtmlAnchor itemTitle = e.Item.FindControl("linkItem") as HtmlAnchor;
            Item srcItem = (Item)e.Item.DataItem;

            itemTitle.InnerText = srcItem["Title"];



            if (srcItem.HasPresentation())
            {
                //itemTitle.HRef = srcItem.Paths.FullPath;
                itemTitle.HRef = Sitecore.Links.LinkManager.GetItemUrl(srcItem);
            }
            else
            {
                var itemChild = ((Sitecore.Data.Fields.MultilistField)srcItem.Fields["Position override"]).GetItems().First();
                itemTitle.HRef = Sitecore.Links.LinkManager.GetItemUrl(itemChild);
            }
            if (srcItem.ID.ToString().Equals(Business.Constants.ItemsID.SearchJobsPage))
            {

                LinkField url = srcItem.Fields[Business.Constants.Fields.LinkUrlSection];
                itemTitle.HRef = url.Url;
                itemTitle.Target = url.Target;
            }


            if (srcItem.ID.ToString().Equals(Business.Constants.ItemsID.FeaturedCaseStudies))
            {
                //Redirect Featured-Case-Studies to Customer-Results
                Item item = Sitecore.Context.Database.Items.GetItem(Constants.ItemsID.CustomerResults);
                itemTitle.InnerText = itemTitle.Title = srcItem[Constants.Fields.Title];
                itemTitle.HRef = Sitecore.Links.LinkManager.GetItemUrl(item);
            }   /* End Defect no 208947 and */
        }
        catch (Exception ex)
        {
            Log.Error(string.Format("ErrorPage_Link_Lis.rptLinkItem_ItemDataBound() - {0}", ex.Message), ex, ex.TargetSite);
        }
    }

}

}`

2 个答案:

答案 0 :(得分:0)

看起来您需要在!IsPostback块中进行数据绑定,而不是每次加载页面。

这里有类似的情况。

"Invalid postback or callback argument" with Databound controls

答案 1 :(得分:0)

我在上面代码的代码审查中得到了它,响应标题:

org.codehaus.jackson

是主要的问题,HttpContext.Current.Response.TrySkipIisCustomErrors = true; HttpContext.Current.Response.StatusCode = 404; HttpContext.Current.Response.StatusDescription = "404 Not Found"; HttpContext.Current.Response.End();的存在在代码中是有害的,并且在网站中的任何类型的连接都不需要它,所以我删除了相同的问题并解决了问题。我已经理解,Response.End()之后的任何代码都不会执行。希望有权这样做。 现在我的错误页面工作正常。

可以从[Response.End() vs HttpContext.Current.ApplicationInstance.CompleteRequest()

获得更多解释