Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

Response.Redirect vs. Server.Transfer - using ~ operator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jasonheath.net@gmail.com - 28 May 2008 20:20 GMT
I apologize in advance for the length of this post. I wanted to get as
much detail as possible in here.

We have 1 web app that contains the functionality to do some single
sign-on logic. The flow is

1. Welcome page
2. Login Page (where the SSO actually occurs)
3. Welcome page
4. Default page

We have a separate web app that also needs to use the SSO
functionality, so rather than duplicating it, it redirects to the
pages within the first app. So the workflow for the second app
becomes

1. Welcome page (App #2)
2. Login Page (App #1 - where the SSO actually occurs, but this time
passing a return URL)
3. Welcome Page (App #1 - still passing the Return URL)
4. Return URL (App #2)

Everything is fine with the first app by itself. Essentially, the last
line in that page is

Response.Redirect("~/Login/Welcome.aspx");

and this works fine. In the second scenario, since the return URL is
being passed, the line becomes

Response.Redirect("~/Login/Welcome.aspx?ReturnURL=http://App2/
default.aspx");

This generates an application error with a message of

"/App1/Login/~/Login/Welcome.aspx?ReturnURL=http://App2/default.aspx"
cannot be found.

So it looks like it sees the '~' as a literal part of the path and
does not actually resolve it correctly in the second scenario. It
looks like it assumes that it needs to append the relative path to the
front of the URL passed to Response.Redirect. If we use
Server.Transfer instead, it works just fine. Does anyone know why this
is the case?
George Ter-Saakov - 28 May 2008 20:37 GMT
I think the problem is that you do not encode URL correctly.
Must be something like
Response.Redirect("~/Login/Welcome.aspx?ReturnURL=" +
Server.UrlEncode(http://App2/default.aspx") );

George.

>I apologize in advance for the length of this post. I wanted to get as
> much detail as possible in here.
[quoted text clipped - 40 lines]
> Server.Transfer instead, it works just fine. Does anyone know why this
> is the case?
Peter Bromberg [C# MVP] - 28 May 2008 20:44 GMT
Response.Redirect actually goes back to the browser and tells the *browser*
to request the new "page". Server.Transfer all happens on the server, and
the new page is simply sent out to the browser, with no new round trip to
the browser at all.
Peter
>I apologize in advance for the length of this post. I wanted to get as
> much detail as possible in here.
[quoted text clipped - 40 lines]
> Server.Transfer instead, it works just fine. Does anyone know why this
> is the case?
George Ter-Saakov - 29 May 2008 13:38 GMT
I want to add....
Do not use Server.Transfer if you do not know all implications...
Response.Redirect and Server.Transfer are not interchangeable.

When using Server.Transfer ASP.NET is actually using new .aspx page (the one
you transferred to).
But the browser still thinks that you are at old .asp page and POST back
will go to old .aspx page......
Hence a lot of problems.....

George.

> Response.Redirect actually goes back to the browser and tells the
> *browser* to request the new "page". Server.Transfer all happens on the
[quoted text clipped - 45 lines]
>> Server.Transfer instead, it works just fine. Does anyone know why this
>> is the case?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.