473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Logging in to one site from another...

Stu
Hi,

I need to post log in details from one web site to another to log the user
in to one of two sites. The user will enter a username and password in to
textboxes on site 'A', and depending on the format of the username they will
be logged in to either site B or site C.

I am generating a form post from the code behind, but the login page I am
posting to returns a code 200 (OK), but no redirect URI - so the original
page just reloads. The form post scripts are working with a third party
site, but I can't see the code that handles the response at their end.

Can anyone point me in the right direction as to why this is not working -
or if this is the right approach!

Thanks in advance,

Stu
---/ snip /-----
'##### The call

Dim d As New StringDictionary
d.Add("Username", txtUserName.Text.Trim)
d.Add("Password", txtPassword.Text.Trim)
Dim MyCookie As String = ""
Response.Redirect(Utils.FormHelper.GetRedirectURL( Utils.FormHelper.PostData("http://MyDomain.com/login.aspx",
d), MyCookie))

'###### The routines

''' <summary>
'''
''' </summary>
''' <param name="SubmissionUrl"></param>
''' <param name="FormData"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function PostData(ByVal SubmissionUrl As String, ByVal
FormData As StringDictionary) As HttpWebResponse

' Build the authentication URI
Dim serverUri As Uri = New Uri(SubmissionUrl)

' Create the request
Dim request As HttpWebRequest = WebRequest.Create(serverUri)

' Set the headers
request.CookieContainer = New CookieContainer()
request.ContentType = "application/x-www-form-urlencoded"
request.Method = "POST"
request.KeepAlive = True
request.AllowAutoRedirect = False

Dim sb As New StringBuilder
Dim iCurrent As Integer = 1
For Each keypair As DictionaryEntry In FormData
sb.Append(keypair.Key & "=" & keypair.Value)
If iCurrent < FormData.Count Then
sb.Append("&")
End If
iCurrent += 1
Next

' Prepare the body of the request with the POST data
Dim body() As Byte = Encoding.UTF8.GetBytes(sb.ToString)

' Set the content length of the request
request.ContentLength = body.Length

' Send the request to the server
Using stream As Stream = request.GetRequestStream()
stream.Write(body, 0, body.Length)
End Using

Return request.GetResponse()
End Function

''' <summary>
''' This method retreives redirected URL from response header and
also passes back
''' any cookie (if there is any)
''' </summary>
''' <param name="webresponse"></param>
''' <param name="Cookie"></param>
''' <returns></returns>
Public Shared Function GetRedirectURL(ByVal webresponse As
HttpWebResponse, ByRef Cookie As String) As String
Dim uri As String = ""

Dim headers As WebHeaderCollection = webresponse.Headers
Dim code As HttpStatusCode
code = webresponse.StatusCode

If ((webresponse.StatusCode = HttpStatusCode.Found) Or
(webresponse.StatusCode = HttpStatusCode.Redirect) Or
(webresponse.StatusCode = HttpStatusCode.Moved) Or (webresponse.StatusCode =
HttpStatusCode.MovedPermanently)) Then
uri = headers("Location")
uri = uri.Trim()
End If

If (headers("Set-Cookie") IsNot Nothing) Then
Cookie = headers("Set-Cookie")
End If

Dim StartURI As String = "http:/"
If (uri.Length 0 And uri.StartsWith(StartURI) = False) Then
uri = StartURI + uri
End If

Return uri
End Function

Oct 17 '06 #1
0 1022

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ravi Shankar | last post by:
Hi all, I have an enterprise application. I am using Apache Log4J for the logging purposes. WHen a request is received by the application, it goes throug servlets and many classes, and the...
5
by: j vickroy | last post by:
Hello, I'm trying to understand the behavior of the Python 2.3 logging module (MS Windows 2k) with regard to RotatingFileHandler. The following script illustrates a puzzling problem. What is...
1
by: j vickroy | last post by:
My system: MSW XP professional Python 2.3.3 logging package: 0.4.9.2 My problem: The log_test3.py script, provided with the logging package distribution, generates an unexpected message: No...
16
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
2
by: MotorcycleIke | last post by:
I tried using WebRequest, but I am unable to simply redirect to an external aspx site and supply the userid and password and press their login button. I got the webrequest to populate a...
1
by: BobLaughland | last post by:
Hi All, I am development an ASP .NET C# web site. Just wondering the best way to implement logging on my web site. (I have a logging class to log database access, exceptions, etc, etc). I...
1
by: s99999999s2003 | last post by:
hi i have defined a function def logger(logfile,msg): import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%a, %d %b %Y...
1
by: ludvig.ericson | last post by:
Quote from the docs: FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s" logging.basicConfig(format=FORMAT) d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}...
6
by: Larry Bates | last post by:
Every time I look at the logging module (up until now) I've given up and continue to use my home-grown logger that I've been using for years. I'm not giving up this time ;-) I find that I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.