Monday, March 26, 2012

May i warn you for bad redirection?

I seen examples using Server.Transfer to move to another page.
However, this seems to send the desired page to the client but also the current page.
Since twice <html></html> is ignored by the browser you can still suffer.
In our case i used it to upload a (text)file.
The save showed the results from both.

Response.Redirect seems to work fine.The difference is that Server.Transfer stops executing the first page and executes the second page to render the result all within the same request to the server. This is why the client browser thinks he is on the first page (the first page is the URl that was requested).

And yes, as you've noticed, with Response.Redirect the browser shows the correct URL because that causes a second request into the server to display the second page.

-Brock
My remark was not about the addressbar (which is a problem indeed)
It's about what get's send to the client.

To be clear, Server.transfer dumps *both* the pages to the client (browser)
You really don't want that..

<html>
page1 stuff
</html>
<html>
page1 stuff
</html>
end of transmission..
Oops.. error :)

<html>
page1 stuff
</html>
<html>
page2 stuff
</html
To be clear, Server.transfer dumps *both* the pages to the client (browser)
You really don't want that..

It would only do this if you're calling Response.Write, which in ASP.NET you wouldn't be doing. You can call Response.Write, but you lose out of many of the features of ASP.NET. So I suspect you're seeing the problem becuase your first page calls Response.Write("<html>...") then calls Server.Transfer.

-Brock

No comments:

Post a Comment