Share via


PassportIdentity.SetOption

PassportIdentity.SetOption

Sets a specific Microsoft® .NET Passport sign-in option.

Syntax

public void SetOption( string strOpt, object vOpt )

Parameters

  • strOpt
    The option to set.
  • vOpt
    The new value for the option.

Example

The following C# example gets and displays the iMode option and shows that it is null immediately after being created. Then it uses the SetOption method to set the iMode option to true and finally gets and displays the iMode option again, showing that the iMode option is set to true.

<%@ 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 - return to the default.asp
 sruURL = sruURL;
}
else {
 //Set the sign-in URL - stay on this page
 sruURL = sthisURL;
}

Response.Write ("<DIV STYLE = 'position:absolute; right:50px'>" + oMgr.LogoTag2(sruURL,3600,true,null,1033,false,null,-1,false) + "</DIV>");
if (oMgr.GetIsAuthenticated(3600,false,false)) {
 //Display the GetOption, set the Option and then display GetOption again.
 Response.Write ("<br>Initially: GetOption('iMode') = " + oMgr.GetOption("iMode"));
 oMgr.SetOption("iMode",true);
 Response.Write ("<br>After set: GetOption('iMode') = " + oMgr.GetOption("iMode"));
}
else {
 Response.Write ("<br>You have not been authenticated within the last hour. Please sign in or exit.");
} // End If GetIsAuthenticated
%>
</HTML>

Remarks

Attempting to exercise the SetOption method for a nonexistent attribute (strOpt) may cause a run-time error.

See Also

Passport PassportIdentity Object | PassportIdentity.GetOption