PassportIdentity.GetLoginChallenge()

PassportIdentity.GetLoginChallenge()

Returns the URL and header information to facilitate a Microsoft .NET Passport sign-in.

Syntax

public string GetLoginChallenge()

Return values

A string representing the .NET Passport login challenge. Returns the URL and header to facilitate a .NET Passport sign-in, but does not automatically direct to the URL.

Example

The following C# example uses the GetLoginChallenge() method to create a Web request and then displays the response.

<%@ Page Language="C#"%>
<%@ Import Namespace = "System.Web.Security" %>
<HTML>
<HEAD><TITLE>Mysample - Exercise - CS</TITLE></HEAD>
<Script language="C#" runat="server">
 string sServer;
 PassportIdentity oMgr;
 string sthisURL, sruURL;

 protected void Page_Load(Object src, EventArgs e) {
  sServer = Request.ServerVariables["SERVER_NAME"];
  oMgr = (PassportIdentity)User.Identity;
  sthisURL = "https://" + sServer + Request.ServerVariables["SCRIPT_NAME"];
  sruURL = "https://" + sServer + "/BriefCS/default.aspx";
 }
</Script>
<%
if (oMgr.IsAuthenticated) {
 //Set the sign-out URL - stay on this page
 sruURL = sthisURL;
}
else {
 //Set the sign-in URL - stay on this page
 sruURL = sthisURL;
}

//The LogoTag2 allows the user to sign in or sign out.
Response.Write ("<DIV STYLE = 'position:absolute; right:50px'>" + oMgr.LogoTag2(sthisURL,100,-1,null,1033,-1,null,-1,-1) + "</DIV>");
Response.Write("<br><br>" + oMgr.GetLoginChallenge());
%>
</HTML>

The preceding example results in output similar to the following:

WWW-Authenticate:Passport1.4lc=1033,id=23248,tw=14400,fs=1,ru=https://localhost/BriefCS/Default.aspx,ct=1018285737,kv=1,ver=2.1.0173.1,tpf=b813b60149f8482dfbe503304fffd07e

Remarks

The returned response header field contains the URL of the calling page, plus a query string parameter containing the .NET Passport Login server with other parameters in the encoded query string. These query string arguments are then processed by the Login server if the user is redirected, and determine whether the Login server can refresh credentials silently or must display the Login form.

When a server receives a request that requires authentication, the server returns a 401 status code message. In that message, the server should include one or more WWW-Authenticate response headers. These headers include the authentication methods the server has available. The fForceLogin parameter, shown as "fs" in the return, is returned as 1 when the Force Sign In box in the Passport Manager Administration utility is selected. No fForceLogin parameter is returned if the Force Sign In box is not selected.

See Also

Passport PassportIdentity Object