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.Data.SqlClient;
using System.Configuration;
using System.Collections.Specialized;


public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            lblReturnUrl.Text =( Request.QueryString["ReturnUrl"]??"").ToString();
            lblSiteID.Text = (Request.QueryString["SiteID"] ?? "").ToString();
            if (lblReturnUrl.Text == ""||lblSiteID.Text=="")
            {
                lblError.Text = "The ReturnUrl or SiteID is missing. Can't proceed.";
                btnLogin.Enabled = false;
                return;
            }
            txtUserName.Focus();
            //provide testing accounts for user to log in
            lblError.Text = "Login credentials:<br>user: johnd    pw: password or user: janed   pw: password";
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            DataTable tbl = Authentication.VerifyCredentials(txtUserName.Text, txtPassword.Text);
            
            if (tbl.Rows.Count>0)
            {
                int MinutesToExpire = 1;//Authentication will expire in 1 minute. Can be set to other values
                ProcessAuthenticationData(tbl, MinutesToExpire, Convert.ToInt16(lblSiteID.Text), lblReturnUrl.Text);

            }
            else
            {
                lblError.Text = "No user with these credentials has been found.";
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message.ToString();
        }

    }
    private void ProcessAuthenticationData(DataTable tbl, int minutesToExpire, int siteID, string returnUrl)
    {
        //place user data into a collection which is easy to handle
        NameValueCollection UserData = Authentication.BuildUserDataCollection(tbl, minutesToExpire, siteID, returnUrl);

        //build all data into a text string so that it can be stored in database
        string UserString = Authentication.SerializeParameters(UserData);

        //Save querystring parameter and user data string
        string AuthenticationID = Guid.NewGuid().ToString().Replace("-", "");
        //save user information. When the third party app calls web service, this information will be retrieved
        Authentication.ExecuteNonQuery("AuthenticationLog_Insert", new object[] { AuthenticationID, UserString});
        
        Response.Redirect(Authentication.WellFormReturnUrl(lblReturnUrl.Text, AuthenticationID));
    }
}

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)

Share

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
Web02 | 2.8.140814.1 | Last Updated 29 Dec 2008
Article Copyright 2008 by Tomz_KV
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid