Solved

How to use Server.Transfer() with Ajax

Posted on 2009-07-13
11
1,493 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
ID: 24847249
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
ID: 24849257
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
ID: 24849329
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
ID: 24849461
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
ID: 24850085
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:exptech
ID: 24850139
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
ID: 24850424
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
ID: 24855598
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
ID: 24862051
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
ID: 24865612
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
ID: 24868767
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

20 Experts available now in Live!

Get 1:1 Help Now