Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Cross Domain/Platform Authentication and Data Transfer

, 29 Dec 2008
Introduces a methodology for authenticating user in cross domain/platform and transferring user data from one site to another during the authentication process.
CrossSiteAuthentication.zip
CrossSiteAuthentication
AuthenticationSite
App_Code
App_Data
CustomerDB.mdf
CustomerDB_Log.LDF
Bin
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll.refresh
Microsoft.Practices.ObjectBuilder.dll
images
line.JPG
Site1.JPG
Site2.JPG
ThirdPartySite
App_Code
App_WebReferences
AuthenticationService
AuthenticationService.disco
AuthenticationService.discomap
AuthenticationService.wsdl
images
line.JPG
Site1.JPG
Site2.JPG
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class LandingPage1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
            return;

        //make sure user is not authenticated when the third party program starts.
        FormsAuthentication.SignOut();

        //request for the AuthenticationID
        string AuthenticationID = Request.QueryString["AuthID"];
        if (AuthenticationID == null)
        {
            lblError.Text = "A required parameter is missing from url. ";
            return;
        }
        //Request p1 and p2 from Url. p1 and p2 are the parameters that the third party app needs
        string p1 = Request.QueryString["Para1"].ToString();
        string p2 = Request.QueryString["Para1"].ToString();
        //additional code here to process the parameters

        //Add a web reference to your app and name it anything you like. Here it is named as AuthenticationService. 
        //declare web service and a reference variable - ReturnMessage
        AuthenticationService.AuthenticationService AuthService = new AuthenticationService.AuthenticationService();
        string ReturnMessage = "";
        DataSet ds = null;
        //Call Web Method: RetrieveUserDataSet
        //success: user authenticated, get a DataSet. 
        //Failure: user not authenticated or Url exipred. Return null and error message.
        try
        {
            ds = AuthService.RetrieveUserDataSet(ref ReturnMessage, AuthenticationID);
        }
        catch (Exception ex)
        {
            lblError.Text += ex.Message.ToString();
        }

        if (ReturnMessage != "")
        {
            lblError.Text += ReturnMessage;
            return;
        }
        if (ds != null)
        {
            //depending on the stored procedure used to retrieve the data
            //The DataSet can contain multiple tables 
            //Write code here to loop through the DataSet
            //insert or update the third party database
            //and then programmatically log in the user 
            //by setting up appropriate cookies and session variables
            //For asp.net form authentication, call SetAuthCookie method
            FormsAuthentication.SetAuthCookie("LoginUser", false);

            //display user data for demo purpose
            gvUserData.DataSource = ds.Tables[0];
            gvUserData.DataBind();
        }
        else
        {
            lblError.Text += ReturnMessage;
        }
   
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //display authentication status
        //display authentication status
        if (!Request.IsAuthenticated)
            lblError.Text = "The user is not authenticated";
        else
            lblError.Text = "The user is authenticated";
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Tomz_KV
Web Developer
United States United States
Web & Database Developer. Design and implement web and database applications utilizing Microsoft and other development tools.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 29 Dec 2008
Article Copyright 2008 by Tomz_KV
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid