views:

214

answers:

4

I have 3 asp.net pages: Search.aspx, Results.aspx and Login.aspx. Now I want anonymous users to be able to search, so everyone can use search.aspx. This page calls

Server.Transfer(Results.aspx)

and therefore shows the results. Now when the user is not logged in, a link to the login page is displayed on the Results page. The problem is: After the login, I want the user to be redirected automatically to the Results page. However I do not succeed so, as the PreviousPage property of Login.aspx is always null. And when I use

Request.UrlReferrer.LocalPath

it's the link to Search.aspx but not Results.aspx. Also, when the user is on the Results page, how do I enable him to go back by clicking a link and all his search input criteria (like in textboxes) on the Search.aspx is still there so he can refine the search after having seen the results? Whenever I send the user back, all user input is lost. I still haven't figured out if I should use a normal hyperlink, a linkbutton and how to retrieve the previous page url or preserve the input data.

I can use AJAX if that is any help, but a "pure" asp.net solution would be preferred.

+3  A: 

When you do a Server.Transfer it is a serverside redirect...meaning the client still sees the original URL. You need to post the search criteria to the results page, store them locally, show the login link. When they are logged in you can redirect to the results page and rehydrate the search critera and show the results.

Andrew Siemer
Response.Redirect actually sends the browser an HTTP 302(?) message, telling the browser to request the specified page. Server.Transfer just executes the new page, rendering and sending it down to the browser, which thinks it's getting the first page since it never issued a GET for the new page. That's why the URL stays the same for the client with Server.Transfer
Josh E
+1  A: 

You can use User.Identity.IsAuthenticated to check if the user is logged in and show/hide the login button based on that.

To keep values for the page, you could store them in Session, then have the Search page look for them and, if they exist, place them in the controls.

Matthew Jones
Thanks for the tip. I now use Session to store all search criteria, works really easier than assumed.
noisecoder
+1  A: 

Try using Response.Redirect("url") instead of Server.Transfer. When you use Server.Transfer, the url on the client will remain the Search page and not actually redirect to the Results.

TheTXI
A: 

You can also embed the URL you want to return to after login into the querystring if you want.

Ian Jacobs