Posting to another server and end up there?

J

John Dalberg

Hello

I have a login form on a page that should post the data to a non Windows
server and upon successful authentication, the browser needs to show the
secodn url.

I did the form post, got the successful results back but the browser is
still showing at the same url. Which method needs to be used so that the
browser shows the target url. In this case it's sURL in my code. sHTML is
the result from the successful result from posting the form to the non
Windows server.

As an example, imagine you want to put a Hotmail login form in your own
site, post the form using your asp.net code and the browser ends up inside
Hotmail showing a hotmail.com url.

Code Snippet:

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "text/html";
Response.Write(sHtml);
Response.RedirectLocation = sURL;
Response.Flush();
Response.Close();


John Dalberg
 
J

John Dalberg

Replace;

Response.RedirectLocation = sURL;

With

Response.Redirect sURL

Response.Redirect is just telling the browser to go to that url and start
fresh. I will lose all my post results that I got earlier.

John
 
S

Steven Burn

Response.Redirect is just telling the browser to go to that url and start
fresh.

I know....
I will lose all my post results that I got earlier.

Not if you place the Response.Redirect after the code that grabs the posted
info.... (I screwed up in my first reply as I wasn't aware of the
Response.RedirectLocation method)

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
J

John Dalberg

fresh.

I know....


Not if you place the Response.Redirect after the code that grabs the posted
info.... (I screwed up in my first reply as I wasn't aware of the
Response.RedirectLocation method)

I am not sure what you're tying to say. A redirect causes my code to go
back to the browser and any code after the redirect is not run.
A redirect is just a get method. The url I am using is for a post method
which expects post data and the post is what gets me logged in. If the url
doesn't get post data, the browser gets an error message. That's what I get
when I used response.redirect.


When I said losing my post results, I meant if I do redirect, the browser
is not going to get the post result and the browser loses it. However the
post result html is in my code in a string.

John
 
M

Mark Schupp

IIRC you are trying to jump directly from a form on your site to another
site. Why can't you just make the target sites user validation script the
action of your form?
 
J

John Dalberg

IIRC you are trying to jump directly from a form on your site to another
site. Why can't you just make the target sites user validation script the
action of your form?

I don't understand what you mean. There's no validation script on the page.

John
 
S

Steven Burn

Oks, put simply, you mentioned that you confirm that everything was oks at
the authorisation level yes? and if everything is oks, you want it to re-dir
to the second URL?

All I'm saying is, do whatever your doing now (that you've said is
working?), and just place the Redirect action, after your authorisation.

For example

'// Your authorisation code goes here

blnSuccess = "somewhere.com/?auth=AuthoriseMe"

'// Where blnSuccess returns 1 for success and 0 or whatever
'// for fail.

If blnSuccess = 1 Then
Response.Redirect strSecondURL
Else
Response.Write "Woops, something went wrong"
End If

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
S

Steven Burn

I don't understand what you mean. There's no validation script on the
page.

I thought you said;

.........post the data to a non Windows
server and upon successful authentication, the browser needs to show the
secodn url.
I did the form post, got the successful results back .......
</snip>

To get a successful authentication, you need to have validation, otherwise,
the authentication is invalid.

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
M

Mark Schupp

Ok, Lets back up a step. A lot of the background info go trimmed and needs
to be re-stated in your next response.

IIRC:

You have a form on your site that is a copy of the login form for another
site.

You want to have data from that form posted to another server for user
authentication.

Then you want to direct the user to another URL. I thought I understood this
URL to be where the user would be taken if they had used the login form on
the other site in the first place. If that is the case then just post your
form to the same place that the form on the other site is posted to. If that
is not the case, please clarify what you need.
 
J

John Dalberg

page.

I thought you said;



</snip>

To get a successful authentication, you need to have validation, otherwise,
the authentication is invalid.

Thanks for the feedback. See my response to Mark.
 
J

John Dalberg

Ok, Lets back up a step. A lot of the background info go trimmed and needs
to be re-stated in your next response.

IIRC:

You have a form on your site that is a copy of the login form for another
site.

You want to have data from that form posted to another server for user
authentication.

Then you want to direct the user to another URL. I thought I understood this
URL to be where the user would be taken if they had used the login form on
the other site in the first place. If that is the case then just post your
form to the same place that the form on the other site is posted to. If that
is not the case, please clarify what you need.

Yes that's what I want to do.
I think I found the issue. I will try something.

John
 
J

John Dalberg

Ok, Lets back up a step. A lot of the background info go trimmed and needs
to be re-stated in your next response.

IIRC:

You have a form on your site that is a copy of the login form for another
site.

You want to have data from that form posted to another server for user
authentication.

Then you want to direct the user to another URL. I thought I understood this
URL to be where the user would be taken if they had used the login form on
the other site in the first place. If that is the case then just post your
form to the same place that the form on the other site is posted to. If that
is not the case, please clarify what you need.

Yes that's basically what I want to do but the browser still shows the
initial url.

I am doing the post to the second location using System.Net.HttpWebRequest
and I get the proper response and I then flush the current
System.Web.httpResponse and pump the response from HttpWebResponse into the
Current Response object. I am not sure if this is the proper way to do it..
It's like cheating because I changed the contents of the response object
but the client, the browser, is not aware now that the response is from the
other url. It thinks the response came from the initial form page.

AFAIK, response.redirect tells the browser to go to a certain url and get
it so basically I am starting at the remote login page, which I do not
want. What needs to happen is the browser needs to think it already logged
in on the other server.

I might just be missing an obvious fact but I am not seeing it.

John
 
S

Steven Burn

AFAIK, response.redirect tells the browser to go to a certain url and get
it so basically I am starting at the remote login page, which I do not
want. What needs to happen is the browser needs to think it already logged
in on the other server.

Am I right in thinking, a cookie is set upon successful authorisation?, if
so, this may be where the problem is as it could quite possibly be a case of
the cookie being tied to your first (login) domain, instead of the domain
you are querying/wanting to go to.

If not, what does the second URL usually use? (cookies, sessions etc?)

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
J

John Dalberg

Am I right in thinking, a cookie is set upon successful authorisation?, if
so, this may be where the problem is as it could quite possibly be a case of
the cookie being tied to your first (login) domain, instead of the domain
you are querying/wanting to go to.

If not, what does the second URL usually use? (cookies, sessions etc?)

There are no cookies set. I cleared the cookie file in Firefox, went to the
second url, logged in, closed Firefox, looked at the cookie file and it was
still empty.

The second url uses an interesting authentication scheme. Once you're
logged in using a form post, all the urls in the links in the next page
have what seems to be your own session id in them.
No cookies and no query strings are used. But I also have the a problem
because the urls are relative

So I guess because it's not using cookies or query string, a redirect won't
work because the browser doesn't know who I am.

Although there's another solution where I create a form dynamically and
sent it to the browser along with a form.submit() Javascript, this depends
on Javascipt enabled browser. That's why I wanted to do it in a pure
asp.net way.

John
 
S

Steven Burn

That's why I wanted to do it in a pure asp.net way.

Ah.... I've a feeling this has contributed to the confusion as this NG is
for classic ASP.

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
C

Chris Hohmann

John Dalberg said:
There are no cookies set. I cleared the cookie file in Firefox, went to the
second url, logged in, closed Firefox, looked at the cookie file and it was
still empty.

The second url uses an interesting authentication scheme. Once you're
logged in using a form post, all the urls in the links in the next page
have what seems to be your own session id in them.
No cookies and no query strings are used. But I also have the a problem
because the urls are relative

So I guess because it's not using cookies or query string, a redirect won't
work because the browser doesn't know who I am.

Although there's another solution where I create a form dynamically and
sent it to the browser along with a form.submit() Javascript, this depends
on Javascipt enabled browser. That's why I wanted to do it in a pure
asp.net way.

Here's an article on reading the contents of a remote web page. Note the
section that talks about adding a <BASE> tag to the returned content.

http://aspfaq.com/show.asp?id=2173

So, you can do two things:
1. Use the above to return the content of the page returned after logging
in, adding the appropriate <BASE> tag

OR

2. Parse the returned content for the pseudo-cookie embedded in each anchor
href/ form action. Then response redirect to the url of the resulting page,
appending the pseudo-cookie to the querystring.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top