PassportIdentity.CryptPutHost
PassportIdentity.CryptPutHost
Sets the key being used for Microsoft® .NET Passport encryption and decryption by referring to the host name or IP number being used by the desired installation.
Syntax
put static int CryptPutHost( string strHost )
Parameters
- strHost
The host name or IP address.
Return values
An integer result code. Returns 0 upon successful completion of the method.
Example
The following C# example sets the keys for the alternate host, www.alternatehost.com.
<%@ 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)) { //User has authenticated within the last hour. Load the alternate key. //If the alternate key is not loaded, the host will //be Request.ServerVariables["SERVER_NAME"]. PassportIdentity.CryptPutHost("www.alternatehost.com"); } else { Response.Write ("<br>You have not been authenticated within the last hour. Please sign in or exit."); } // End If GetIsAuthenticated %> </HTML>
Remarks
This method should be used only if your site has multiple keys installed because there are multiple sites being served by common installations.
To determine the host being used by a current page, use the Request.ServerVariables["SERVER_NAME"] method.
This method allows the use of a different set of keys based on a host name.
Setting keys for the PassportIdentity object has no effect on the keys used for Ticket and Profile decryption by the PassportIdentity object. The PassportIdentity object loads the correct key for the current request either by determining host name through objects (through the built-in OnStartPage method) or through the structures passed to equivalent PassportIdentity ISAPI-targeted application programming interfaces (APIs).
See Also
Passport PassportIdentity Object | PassportIdentity.CryptPutSite | PassportIdentity.CryptIsValid