Click here to Skip to main content
14,040,363 members
Click here to Skip to main content
Add your own
alternative version

Stats

5.7K views
2 bookmarked
Posted 5 Feb 2010
Licenced CPOL

ASP.NET : __VIEWSTATE Bug !

, 13 Oct 2013
Rate this:
Please Sign up or sign in to vote.
When you Try this on Asp.net 2.0 WebSite:http://www.YouWebsite/default.aspx?__VIEWSTATE=COUCOU!You will have something like that:Server Error in '/'

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

When you Try this on ASP.NET 2.0 WebSite:

http://www.YouWebsite/default.aspx?__VIEWSTATE=COUCOU! 

You will have something like that:

Server Error in '/' Application.

Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

the Rose Solution Rose is to Remove __VIEWSTATE parameter From Request.QueryString

protected override void OnInitComplete(EventArgs e)
{
    base.OnInitComplete(e);

    if (Request.QueryString.ToString().Contains("__VIEWSTATE"))
    {

        // reflect to readonly property
        PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);

        // make collection editable
        isreadonly.SetValue(this.Request.QueryString, false, null);

        // remove
        this.Request.QueryString.Remove("__VIEWSTATE");


        // make collection readonly again
        isreadonly.SetValue(this.Request.QueryString, true, null);

    }

} 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ASP.NET Community
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
Group type: Collaborative Group

760 members


You may also be interested in...

Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190425.1 | Last Updated 13 Oct 2013
Article Copyright 2010 by ASP.NET Community
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid