开发者

System.Web.HttpException: Unable to validate data - after publishing site

I have written the following code for login:

 Session["IsLogin"] = false;
        System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        if (txtPassword.Text.Trim() == string.Empty)
        {
            // Display Error
        }
        else
        {
            string Pwd = config.AppSettings.Settings["PWD"].Value.ToString();
            FormsAuthenticationTicket formAuthTk = FormsAuthentication.Decrypt(Pwd);
            string strDcryptedPwd = formAuthTk.Name.Trim().ToString();
            if (txtPassword.Text.Trim() == strDcryptedPwd)
            {
                Session["IsLogin"] = true;
                Response.Redirect("AnyPage.aspx");
            }
            else
            {
                // Error, Wrong password
            }
        }

Which is running fine while running through Visual studio. But when I published it it is showing the below error:

System.Web.HttpException: Unable to validate data

NOTE:

  1. I publish the application on the same server on which I am developing the site.

  2. I have tried EnableViewStateMAC = false o开发者_开发问答n page level. [Login Page]

What is the reson of this error? Why it is only appears when I have published the site?


I have changed the way to encrypt the string and the problem disapperars. I have no idea about the reason of the error, but I resolved it like this. Hope it will help to others, who are facing the same issue.


you do not need to declare the config in the way you did, just use Configuration.AppSettings["PWD"].ToString()...


see here:

How to: Read Application Settings from the Web.config File

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜