Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

purpose for <pages enableEventValidation="false">

Tags:

asp.net

I've used the following in web.config

<pages enableEventValidation="false">

This corrects a problem we've been having with Ajax.

We have a web page that if you browse to directly using a standard HTML hyperlink works fine.

If you browse to the page from another page via link inside a gridview and response.redirecting in the RowCommand event to the page passing an ID in the querystring. The page throws errors from controls inside the panel stating

"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'm happy to leave the page validation as false as it seems to have had no other effect.

Any ideas what's happening?

like image 902
Robert Avatar asked Oct 01 '09 12:10

Robert


People also ask

Why we use EnableEventValidation?

When the EnableEventValidation property is set to true , ASP.NET validates that a control event originated from the user interface that was rendered by that control. A control registers its events during rendering and then validates the events during postback or callback handling.

What is EnableEventValidation true?

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.

What is Eventvalidation?

Event Validation is a new feature in ASP.NET 2.0 which provides an additional level of checks on postback actions. It verifies whether a postback from a control on client-side is really from that control and not from a malicious person trying to break your application.


2 Answers

Read the documentation.

EDIT: For security reasons, it's probably best to leave it set to true wherever you can.

I would therefore recommend that you set it to false only on the individual AJAX pages where it causes problems, while leaving it true in web.config.

like image 141
SLaks Avatar answered Oct 13 '22 16:10

SLaks


From here

Invalid PostBack or CallBack argument error is basically raise because of Event Validation feature. The EventValidation feature is a new feature in ASP.NET 2.0, and provides an additional level of checks to verify that a postback from a control on the client is really from that control and not from someone malicious using something like a cross-site script injection to try and manipulate things. It is part of our overall strategy of increasingly adding security in depth levels to the programming model -- so that developers can be secure by default even if they forget to add security checks of their own.

Now, Invalid PostBack or CallBack argument error may occur when you are firing click event and the object is rebinding or its properties are changed in Page_Load event or someone is trying to hack into your system with cross site scripting. Each time .Net Framework render a page then it associate a unique Guid for all the controls. When binding a gridview or repeater, on each databind framework will associate a new guid for the contorl. So every time when you are firing event make sure Page_Load event does not change the control, because if the control changed the it will have a different Guid which have acutally fired the event for postback. Here are some scenario with this error.

1) Invalid Postback or Callback argument in GridView Problem may be: You are binding data in Page_Load event with either Object Data Source or Manual Binding with function call. This will make your GridView bind data on every event fire of any control. When you are firing any GridView command with OnRowCommand, before RowCommand fire your GridView will rebind and all control within it will be assigned to new id. So RowCommand could not get the item which have fired the event. Solution for Invalid Postback or Callback argument in GridView: You can bind your data within this if condition

   if (!IsPostBack)

   {

          //Your code for Bind data 

   }

This code will definitely give you solution if this not work then check whether any other control is not giving error.

like image 7
rahul Avatar answered Oct 13 '22 16:10

rahul