如何解决:无效的回发或回调参数

时间:2017-06-13 10:53:59

标签: c# asp.net validation client

我创建了一个Web应用程序,用户可以选择重置他/她的密码。

当他点击重置密码时......会向他发送一封电子邮件,其中包含重设密码的链接..

点击链接后,进入更改密码页面。 用户输入新密码的地方..

我在aspx UI页面中有以下字段:

<div id="changePassDiv">
<div>
<asp:TextBox ID="txtNewPassword" TextMode="Password" runat="server" class="form-control input-sm" placeholder="" TabIndex="1"></asp:TextBox>
</div>

<div>
<asp:TextBox ID="txtConfirm" runat="server" class="form-control input-sm" TextMode="Password" placeholder="" TabIndex="1"></asp:TextBox>
<asp:CompareValidator ID="cmp" runat="server" ControlToValidate="txtConfirm" ControlToCompare="txtNewPassword" ErrorMessage="Password doesn't match!" Display="Dynamic"></asp:CompareValidator>
</div>

<div><asp:Button ID="SubmitButton" runat="server" Class="btn btn-default-color btn-sm" Text="Submit" OnClick="SubmitButton_Click" OnClientClick="ga('send', 'event', 'contact', 'Click', 'Submit');" CausesValidation="true" ValidationGroup="DetailsGroup" /></div>

</div>

我在aspx.cs后面的代码:

public partial class reset : System.Web.UI.Page
{
string userName = ""; string useremail = "";
protected void Page_Load(object sender, EventArgs e)
{
    if (Request["email"] != "" && Request["email"] != null)
    {
        useremail = Server.UrlDecode(DLSecurity.DecryptString(Request.QueryString["email"].ToString()));
    }
    if (!Page.IsPostBack)
    {

    }

}


protected void SubmitButton_Click(object sender, EventArgs e)
{

    try
    {
        if (useremail == "")
        {
            return;
        }
        userName = Membership.GetUserNameByEmail(DLSecurity.EncryptString(useremail));
        MembershipUser mu = Membership.GetUser(userName);

        string password = mu.ResetPassword();
        if (mu.ChangePassword(password, txtNewPassword.Text))
        {
            InvalidCredentialsMessage.Text = "Password changed successfully!";
            InvalidCredentialsMessage.ForeColor = Color.Green;
            InvalidCredentialsMessage.Font.Size = 12;
            ScriptManager.RegisterStartupScript(this, GetType(), "Success", "alert('Please enter your Username/Email Id!');", true);
            //ClientScript.RegisterStartupScript(this.GetType(), "redirect user to homepage", "alert('password changed successfully. you are being redirected to homepage.');window.location.href='/homepage';", true);
        }
        else
        {
            InvalidCredentialsMessage.Text = "Password is not changed please try again!";
            InvalidCredentialsMessage.ForeColor = Color.Red;
            InvalidCredentialsMessage.Font.Size = 12;
        }
    }
    catch (Exception ex)
    {

        InvalidCredentialsMessage.Text = ex.Message;
        if (ex.Message.ToLower().IndexOf("non alpha numeric characters") != -1)
            InvalidCredentialsMessage.Text = "Password should consist of minimum 7 characters with atleast one capital alpahabet, one small alphabet, one special character and one numeric value";
        if (ex.Message.ToLower().IndexOf("value cannot be null") != -1)
            InvalidCredentialsMessage.Text = "you are trying to change another user password!";
        InvalidCredentialsMessage.ForeColor = Color.Red;
        InvalidCredentialsMessage.Font.Size = 9;
    }
}
}

当用户点击电子邮件中的重置链接时,它会更改密码窗口,当他填写新密码&amp;点击提交,它会抛出以下错误:

  

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

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.ArgumentException:无效的回发或回调参数。使用配置或&lt;%@ Page EnableEventValidation =“true”%&gt;启用事件验证在一个页面中。出于安全考虑,此功能可验证回发或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证。

  

来源错误:

     

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

堆栈追踪:

[ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> 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.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +11859663
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +143
   System.Web.UI.WebControls.HiddenField.LoadPostData(String postDataKey, NameValueCollection postCollection) +54
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +580
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +931
  

注意:我尝试添加&lt;%@ Page EnableEventValidation =“true”%&gt;但它没有工作

0 个答案:

没有答案