|
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 LandingPage2 : 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["Para2"].ToString();
//additional code here to process the parameters based on business logic
//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
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.
Web & Database Developer. Design and implement web and database applications utilizing Microsoft and other development tools.