Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Posting data to another application, especially Outlook Web AccessPosting data to another application, especially Outlook Web Access
Previous
 
Next
New Post
8/20/2006 9:59 AM
 

I recently struggled to find a solution that would allow our DNN app to achieve single sign-on with other applications, especially Outlook Web Access.  Since all of the applications use Active Directory for authentication, once a user logs into the DNN app they don't have to enter their username or password again for other apps, even when they are connecting from a public computer.

 

Now that I have figured it out (with the help of people on several different forums) I thought I would share my code with everybody else.

I created a class that creates an HTML form with data fields and posts the form to another URL.  This class can be used to post to any form with whatever data fields are necessary.  You can also choose whether you want the url that your app is posting to to open in a new window or not.

(In order to be able to use this code, your Exchange server has to be set up to use forms-based authentication.)

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 ' End CrossPost Class

I originally had code that called this class in a custom module in my DNN app.  The problem with this was that, although it worked, it caused my DNN page to be left completely blank after the new window opened and the user was forced to click the Back button on the browser to bring the DNN page back.  I moved the code into the load event of a blank page in my DNN app and just included a link to this page in my DNN app.  This way the DNN page is not left blank after the new window opens.  The user will see the url change from the url of the page in your DNN app to the url of the app that you are posting to.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

Dim postToOWA As New CrossPost()

'Retrieve the user info from DNN

Dim currentUser As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo

postToOWA.AddField("username", currentUser.Username)

postToOWA.AddField("password", currentUser.Membership.Password)

postToOWA.AddField("destination", "https://YOUR_SERVER_NAME/exchange/")

postToOWA.AddField("flags", "0")

postToOWA.PostDataToForm(Url:="https://YOUR_SERVER_NAME/exchweb/bin/auth/owaauth.dll", _

FormName:="logonForm", OpenLinkInNewWindow:=False)

Catch xcp As System.Threading.ThreadAbortException

'The Response.End statement causes this exception but should be ignored

Catch xcp As System.Exception

Response.Write("Unable to connect to the other application using Single Sign-On at this time.")

'Log the exception

Dim logController As New Log.EventLog.ExceptionLogController

logController.AddLog(xcp, Log.EventLog.ExceptionLogController.ExceptionLogType.PAGE_LOAD_EXCEPTION)

End Try

End Sub

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Posting data to another application, especially Outlook Web AccessPosting data to another application, especially Outlook Web Access


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out