Jeffrey Palermo (.com)

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Obvious compatibility bug in .Net 2.0 Beta 1 - your v1.1 code won't work - level 100

This post is to share a backwards compatibility bug in v2.0 Beta 1.  I ran into this bug when porting a project of mine.  This wasn't the only issue, but here it is.  Run this page under v1.1 and click the button to your heart's content:

<%@ Page%>

<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button>
</form>
</body>
</HTML>
<script runat="server">
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer(Request.Path, true);
}
</script>

Now, run this page under v2.0.  You will click the button, and your computer will never return the page.  It will lock up.  But really it's not.  Your computer is in an infinite loop.  This is because the second parameter of Server.Transfer has been changed. 

  • When set to true, in v1.1, the querystring would be preserved.
  • In v2.0, the form values are preserved as well.
  • Because the button element is a form element, the button submit is transfered also, so the page thinks that every run is a postback, so the page keeps Server.Transfer()ing back to itself until you kill it.

It's nice that Microsoft added functionality, but we really just need another overload.  Leave the method like v1.1 because this broke my project, so I'm sure it will break some other projects.  Add an overload to accept a third parameter as a boolean which dictates whether to preserve the form values:

Server.Transfer(Request.Path, true, false);

I would use the above so that my querystring would be preserved but the form values would not.



Posted 08-20-2004 1:14 PM by Jeffrey Palermo

[Advertisement]

Comments

Chad Smith wrote re: Obvious compatibility bug in .Net 2.0 Beta 1 - your v1.1 code won't work - level 100
on 08-21-2004 3:31 PM
Thanks for the heads-up and time taken to blog this. I believe this will be of use to me in the near future.

K.Senthil Kumar (Sensoft2000) wrote re: Obvious compatibility bug in .Net 2.0 Beta 1 - your v1.1 code won't work - level 100
on 08-22-2004 2:18 PM
Wow. Very nice article..
How microsoft allow this?.
Veerakumar wrote re: Obvious compatibility bug in .Net 2.0 Beta 1 - your v1.1 code won't work - level 100
on 08-22-2004 5:29 PM
Hi,

It is really super. Thank you for ur information.

Regards,
msveera
Maria Tverdostup (Microsoft) wrote re: Obvious compatibility bug in .Net 2.0 Beta 1 - your v1.1 code won't work - level 100
on 09-15-2004 6:24 AM
Hi,

No doubts that this is a confusing topic. The KB article on the latest v1.1 behaviour should be published on MSDN or it will be there soon if not. Anyhow, this is what v1.1 with the latest fixes or v1.1 SP1 will do:

1) when POSTing to the same page with the 2nd parameter set into FALSE both query string and form data collection WILL NOT be preserved.
2) when the 2nd parameter is OMITTED query string WILL NOT be preserved, form data collection WILL.
3) when the 2nd parameter is set into TRUE both form data collection and query string WILL be preserved. Hence expect stack overflow if POSTing to the same page.

There should be 2 parameters to implement this logic, you are absolutely correct. We should consider more elegant set of Server.Transfer() methods in v2.0.

Hope this helps to clarify things.
Maria
sarvjeet ahuja wrote re: Obvious compatibility bug in .Net 2.0 Beta 1 - your v1.1 code won't work - level 100
on 01-20-2005 1:25 AM
If you have .Net framework 1.1 (without any service pack), server.transfer to the same page keeps IsPostBack to false. After applying service pack 1 to .Net framework 1.1, same code shows IsPostBack to true.

This has broken a lot of applications of ours.