I have sucessfully redirect one of my page to 404 error page using redirection in sitecore. Problem is when i am selecting any country from dropdown list i am getting below error :
"Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page.
For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."
I don't want to compromise with security by setting 'enableEventValidation = false'
. By doing so its working fine but i am in need of some alternate solution. And, yes my dropdown binding is inside !postback
too.
and even I tried to register ClientScriptManager.RegisterForEventValidation method as suggested in one of blog but it did not worked.
Some code part of 404 page is :
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);
}
}
}
}`