viewstate is invalid for this page...

J

Joe Stampf

I have come across a problem where I would like to post my form data to an
aspx page different from the one that is posting. Nothing unusual, right?

The problem is that you can't do this when you are using viewstate! b/c the
hidden viewstate field gets posted along with your data. When it hits the
target page, asp.net validates it, sees it is a viewstate from a different
page, and throws an exception.

Is there something I'm missing, something to 'turn off' to bypass this
problem that shouldn't be a problem?

Note that there is a page directive 'ValidateViewstate' that you can set to
false (off), but there are 2 problems preventing me from using this (1) it
opens your app up to considerable risk from attackers, and (2) it didn't
work -- it still generated the exception.

Also note that I could declare a different form in the client to house and
post my data, but this is not an option for me b/c I need to use the
server-side form (only one is allowed) to house the controls whose data is
being posted.

Hope someone can help...
 
J

Joe Stampf

In case anyone is interested, it seems the solution is a page dirctive
called EnableViewStateMac that can be set to false in the aspx to disable
hashing of the viewstate.

I haven't tried this yet, my actual solution was to do pos back to the same
page and then server.transfer to a page specified in the url request string.
Either method is viable.

The server.transfer has some nice features, such as you don't see the url of
the actual page being displayed in the browser, also the filename of the
page is encoded in the url, so the client never sees the real filename, a
nice little security feature.

Fore example, the url looks like:
"http://www.mysite.com/home.aspx?item=bob&page=detail"

The server code looks up the real page filename based on the keyname
'detail', and then does the server.transfer to that.
 
D

dolan

Joe,

In asp.net the normal way of doing things isnt really to post a form t
another page. Let the page post back to itself, then you can so
server.transer to whereever you want to go, you can access the for
variables from the new page if you use server.transfer. Or you can pu
them in HttpContext.Current.Items which stays alive during your htt
request


-
dola
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,121
Messages
2,570,712
Members
47,282
Latest member
hopkins1988

Latest Threads

Top