Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1610
  • Last Modified:

How to use Server.Transfer() with Ajax

We are having a problem using the Server.Transfer() method on a page that is using Ajax updating. Please excuse my somewhat limited knowledge of ASP.net, being I am an application developer, and have only recently started developing web apps. The web app I am designing requires a very high degree of security due to it's legal nature. To try and increase the security of the site, I do not want any page address, other than the login page itself to show up in the browser address bar, or current page source code if read by the users. They should have absolutely no knowledge of the structure of the site itself, and no way to directly go any page on the site, if not brought there in code, EVEN if they are logged in, including the use of the back button in the browser. Furthermore some page names will be generated dynamically using GUIDs. My understanding is that this can be accomplished by using the Server.Transfer() method, but when trying to use it with a page that contains Ajax update panels, we receive an error in the browser. I believe this is being caused by the panel expecting data to be returned and the method seems to confuse the panel. I have tried to flush the data, by manually updating the panel, and I have also tried to flush and clear the Response, nothing seems to work. Of course if I use the Response.Redirect() method it works, but then the page address shows up in the browser, which is exactly what I do not want.

Thanks is advance, and sorry about the verbose explanation.
0
exptech
Asked:
exptech
  • 7
  • 4
1 Solution
 
orbulatCommented:
um... if you wish to secure your pages without letting users know the page names / structure
why don't you use url rewrite?
or simply using one page, render all page content within one page (content is varied by things like querystrings)

if u wish to use url rewrite, u can try this
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
0
 
exptechAuthor Commented:
orbulat, I tried them, but I am still getting the same error as if I use the Server.Transfer() method.
0
 
exptechAuthor Commented:
I included a limited screen shot of the actual error being reported by IE7. When using the Server.Transfer() method, or the one's that you had suggested, the page just refreshes, and at the bottom of IE it say errors on this page. When you click on the errors, the screen shot is what it reports.


Error.gif
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
orbulatCommented:
oh sorry, wait. i guess i suggested sth. wrongly above, i overlooked the error message.

you have a look
http://forums.asp.net/p/1078772/1788445.aspx
and
http://blog.dreamlabsolutions.com/post/2008/10/06/Server-Transfer-in-an-UpdatePanel.aspx
0
 
exptechAuthor Commented:
orbulat, thank you for the quick responses, but these links still are not what I need. The first link shows how to do it with javascript, the problem is the page that you want to navigate to needs to be put into the script itself, if I am understanding it correctly. That defeats the purpose of hiding the page links, the user can see it in the returned page source code.

The second link, explains why you can't do it, and suggests a workaround, the problem is the workaround defeats the whole idea of the update panel, and refreshes the whole page.

The main page is a login page with an update panel containing the login information. If it is incorrectly entered the user is notified in the update panel, WITHOUT having to refresh the whole page, giving a much nicer user experience, and since the login page contains many hi-res jpgs, it saves a lot of bandwidth.
0
 
exptechAuthor Commented:
I am thinking there has to be a way to cancel the async return of the data to the panel, or maybe get rid of the panel itself, since the transfer would happen if the user properly logs in, so there would be no more need for the page itself, and it's controls. As I stated earlier I tried a manual update before the server.transfer() method, but that did not work. I also tried to flush and clear the response, again, no luck.
0
 
exptechAuthor Commented:
Ok, I came up with a workaround, but it is not an elegant solution by any means. What I did was to put a timer control on the page, and set it's enabled property to false, and it's interval to 1. When the login button is clicked in the update panel, I simply set the timer enabled property to true, let the button click event finish, then when I receive the tick event from the timer, then I call the server.transfer() method. It works great, but I think there is a more efficient way to do this. It seems that the problem arises when you call the server.transfer method inside of the button click event, so now what I am thinking of trying is to cancel the actual button click event from inside the event, then call the server.transfer method. Is it possible to cancel a button click event from inside itself ? If so, do you know how this is done ?
0
 
orbulatCommented:
good that u found an alternative
just a quick thought, since updatepanel + server.transfer will cause the problem
how about checking the login in another way?
http://weblogs.asp.net/andrewfrederick/archive/2008/02/18/a-client-side-ajax-login-for-asp-net.aspx
0
 
exptechAuthor Commented:
I also developed another workaround, much more elegant than the first. The link you provided was not any better than my solution, but did help me with another part of the app, so I awarded you the points.

One final question, do you know if you can cancel the button click event from within the event itself?

If so, how?

Thanks
0
 
orbulatCommented:
haha, sorry couldn't help eventually :p
what solution did u come up finally?

cancel button event? how about this one?
http://forums.asp.net/p/916012/1039462.aspx
and
http://forums.asp.net/p/1123623/1761639.aspx
0
 
exptechAuthor Commented:
I wound up still using an Ajax update panel, where the login information is sent to the server, if it is not valid then I just update the panel with a message. On the other hand if the login is valid, I store the page I want to send the user to in a session variable. Then I use Response.Redirect, which works fine with Ajax, to send the user to a new page, that I named Main.aspx. This page has no visual components to it, but in it's page_load event, I read the session variable containing the desired page for the user,  then from this page I do a server.transfer to this page. I use this main page as a sort of routing hub for all other pages. The effect is that after logging in the user only sees http://sitename/Main.aspx for the rest of their session, regardless of the actual page I am displaying.  Being I store all information needed between pages on the server side, I have no problem with passing info between the pages. Works great.

Thanks for the other links, I am going to check them out.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now