Solved

How to use Server.Transfer() with Ajax

Posted on 2009-07-13
11
1,469 Views
Last Modified: 2012-05-07
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
Comment
Question by:exptech
  • 7
  • 4
11 Comments
 
LVL 10

Expert Comment

by:orbulat
Comment Utility
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
 

Author Comment

by:exptech
Comment Utility
orbulat, I tried them, but I am still getting the same error as if I use the Server.Transfer() method.
0
 

Author Comment

by:exptech
Comment Utility
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
 
LVL 10

Expert Comment

by:orbulat
Comment Utility
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
 

Author Comment

by:exptech
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:exptech
Comment Utility
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
 

Author Comment

by:exptech
Comment Utility
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
 
LVL 10

Accepted Solution

by:
orbulat earned 500 total points
Comment Utility
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
 

Author Comment

by:exptech
Comment Utility
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
 
LVL 10

Expert Comment

by:orbulat
Comment Utility
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
 

Author Comment

by:exptech
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now