Ektron CMS400.NET API Documentation
|
This method allows you to log a user into a server by passing their username, password, and server name. You can also log in an Active Directory user by providing the username, password and domain. Note: When when using Active Directory, the ServerName and Protocol parameters are set to empty strings ("").
public UserData LogInUser(String username, String Password, String ServerName, String Domain, String Protocol);
Public Function LogInUser(ByVal username As String, ByVal Password As String, ByVal ServerName As String, ByVal Domain As String, ByVal Protocol As String) As UserData
Parameters |
Description |
username |
The system username. |
Password |
The system password. |
ServerName |
The system server name. When using Active Directory, this parameter needs to be an empty string "". |
Domain |
The user's domain, required only when users login using Active Directory. If your domain is intra.example.com, it is entered in the following format: "DC=intra,DC=example,DC=com". |
Protocol |
This property is always set to an empty string "". This parameter is only required when using Active Directory. |
Ektron.Cms.UserData
The following example shows how to create a Web page that programmatically logs a user into CMS400.NET. Please note that the code-behind in this example does not login a new user if someone is already logged into the Workarea. This example uses some standard drag and drop controls and a small section of VB code utilizing the LogInUser method. This method uses the InternalAdmin to log the user into CMS400.NET. In the first section, we will deal with the standard drag and drop controls. In the second, we'll deal with the code behind.
1. Between the form tags, add a label to show where the Username is entered. <asp:Label ID="Label6" runat="server" Text="Username: " Width="76px"></asp:Label> 2. Add a text box to enter the Username. <asp:TextBox ID="txtUserName" runat="server" Width="134px"></asp:TextBox> 3. Add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the Username box. <asp:RequiredFieldValidator ID="rfvUserName" runat="server" ErrorMessage="Please enter user name" ControlToValidate="txtUserName">Please enter user name</asp:RequiredFieldValidator> 4. Add two breaks for spacing purposes. <br /><br /> 5. Add a label to show where the Password is entered. <asp:Label ID="Label8" runat="server" Text="Password: " Width="76px"></asp:Label> 6. Add a text box to enter the Password. <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="134px"></asp:TextBox> 7. Add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the password box. <asp:RequiredFieldValidator ID="rfvPassword" runat="server" ErrorMessage="Please enter password" ControlToValidate="txtPassword">Please enter password</asp:RequiredFieldValidator> 8. Add two breaks for spacing purposes. <br /><br /> 9. Add a button to submit the user's login information. We will add a button click event in the code behind. <asp:Button ID="btnLogin" runat="server" Text="Login" Width="57px" /> 10. Add two last breaks for spacing purposes. <br /><br /> 11. Add a results label to display a message that states whether the user is logged in. <asp:Label ID="lblResult" runat="server" Width="432px"></asp:Label>
Add the following information to the code behind of your aspx.vb page.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim api As New Ektron.Cms.CommonApi If (api.RequestInformationRef.CallerId > 0) Then lblResult.Text = api.RequestInformationRef.LoggedInUsername & " is logged in." & <"br/>" End If End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim userAPI As New Ektron.Cms.API.User.User
Dim api As New Ektron.Cms.CommonApi
Dim userObj As UserData
Try If (api.RequestInformationRef.CallerId > 0) Then lblResult.Text = api.RequestInformationRef.LoggedInUsername & " is already logged in."
Else
userObj = userAPI.LogInUser(txtUserName.Text.Trim, txtPassword.Text.Trim, "localhost", "", "")
If userObj.Id = 0 Then lblResult.Text = "Login failed." Exit Sub End If
userAPI.SetAuthenticationCookie(userObj) Response.Redirect(Request.Url.ToString) End If
Catch ex As Exception lblResult.Text = ex.Message End Try End Sub
Copyright (c) 2008. All rights reserved.
|
What do you think about this topic? Send feedback!
|