Server.Transfer() causes an error

  • Thread starter Thread starter yma
  • Start date Start date
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()
 
Here is more info. Only if I use true in Server.Transfer("form2.aspx",
true) will cause the error. Please try yourself.
 
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.
 
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
 
Back
Top