My bad, I should have included a more complete explanation and my code in the original post! I have a class that I use to generate the string for an HTML form, including hidden data fields and submit it to another URL. I use that class to create a form to submit the username and password values to pass to the login form of another app. All of these apps use Active Directory for authentication, but they have to work when the user is on a public computer, so we can't rely on Windows authentication.
I might be able to use your something like your example to create an aspx page that uses this code, if I can safely pass the username and password to this page (ie not in the query string). Then I could have a link in my portal that opens this page. Are you actually transferring the data to another aspx page? If so, could you show me how you do that?
Thanks in advance for you help.
Sheila
My code:
Public Class CrossPost
'Collection to hold the field names and their values
Private fieldNames As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection
'Add a new field name/value pair to post the other form
Public Sub AddField(ByVal name As String, ByVal value As String)
fieldNames.Add(name, value)
End Sub
''' <summary>
''' Posts the data to the url with hidden data fields
''' </summary>
''' <remarks></remarks>
Public Sub PostDataToForm(ByVal Url As String, ByVal FormName As String, ByVal OpenLinkInNewWindow As Boolean)
Try
If OpenLinkInNewWindow Then Url = Url & """ target='_blank'"
System.Web.HttpContext.Current.Response.Clear()
System.Web.HttpContext.Current.Response.Write(
"<html><head>")
System.Web.HttpContext.Current.Response.Write(
String.Format( _
"</head><body onload=""document.{0}.submit();history.back"">", FormName))
System.Web.HttpContext.Current.Response.Write(
String.Format( _
"<form name=""{0}"" method=""{1}"" action=""{2}"" >", FormName, "POST", Url))
'Add the fields/values to the response
For Each value As String In fieldNames.Keys
System.Web.HttpContext.Current.Response.Write( _
String.Format("<input name=""{0}"" type=""hidden"" value=""{1}"">", _
value, fieldNames(value)))
Next
System.Web.HttpContext.Current.Response.Write(
"</form>")
System.Web.HttpContext.Current.Response.Write(
"</body></html>")
System.Web.HttpContext.Current.Response.End()
Catch xcp As System.Threading.ThreadAbortException
'Swallow this exception. Response.End always causes this, but it
' doesn't effect anything.
Catch ex As Exception
Throw
End Try
End Sub
End Class
Protected Sub imgOWA_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgOWA.Click
Dim postToOWA As New CrossPost()
postToOWA.AddField("username", Me.UserInfo.Username)
postToOWA.AddField(
"password", Me.UserInfo.Membership.Password)
postToOWA.AddField(
"destination", "https://YOUR_SERVER_HERE/exchange/")
postToOWA.AddField(
"flags", "0")
postToOWA.PostDataToForm(Url:=
"https://YOUR_SERVER_HERE/exchweb/bin/auth/owaauth.dll", _
FormName:=
"logonForm", OpenLinkInNewWindow:=True)
End Sub