Server.Transfer() causes an error

Y

yma

Hi,

I put a .aspx page inside Server.Transfer() within a button. The page was
created for testing so it only has button and I did not add code. When I
click the button, it gave me an error below. Could try this and help me?
Thank a lot. --Chris

Server Error in '/mysite/WebApplication1' Application.
----------------------------------------------------------------------------
----

The View State is invalid for this page and might be corrupted.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The View State is invalid for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): The View State is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
System.Web.UI.Page.LoadPageViewState()
System.Web.UI.Page.ProcessRequestMain()
 
Y

yma

Here is more info. Only if I use true in Server.Transfer("form2.aspx",
true) will cause the error. Please try yourself.
 
K

Kaustav Neogy

Hi Chris,

One possible reason for this can be same form names. Check
the view source of the page and see that it doesn't have
duplicate form names.

Kaustav Neogy.
 
H

Hans Kesting

yma said:
Hi,

I put a .aspx page inside Server.Transfer() within a button. The page was
created for testing so it only has button and I did not add code. When I
click the button, it gave me an error below. Could try this and help me?
Thank a lot. --Chris

Server Error in '/mysite/WebApplication1' Application.
-------------------------------------------------------------------------- --
----

The View State is invalid for this page and might be corrupted.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The View State is invalid for
this page and might be corrupted.

Source Error:

This is because all the Form fields are sent along with the Transfer,
including
the "__VIEWSTATE" hidden field which stores the (you guessed it) viewstate.


From MSDN:

public void Transfer(
string path,
bool preserveForm
);

If you set preserveForm to true and if the enableViewStateMac attribute of
the <pages> Element configuration element is true, ASP.NET will raise an
exception when Transfer is executed because the view state from the page
that calls Transfer is not valid on the destination page. One of the
preserved form fields on the calling page is the hidden __VIEWSTATE form
field, which holds the view state for the page. When enableViewStateMac is
true, ASP.NET runs a message authentication check (MAC) on the view state of
the destination page when the page is posted back from the client and the
check will fail. For security purposes, you should keep the
enableViewStateMac attribute set to true but there are other methods
available to transfer Forms data. For more information, including
recommended solutions, see article Q316920, "View State is Invalid Error
Message When You Use Server.Transfer" in the Microsoft Knowledge Base at
http://support.microsoft.com.Hans Kesting
 

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

Top