Share via


LoginForms.Login method

Log on the specified user with Forms authentication by Project Server.

Namespace:  WebSvcLoginForms
Assembly:  ProjectServerServices (in ProjectServerServices.dll)

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/LoginForms/Login", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function Login ( _
    username As String, _
    password As String _
) As Boolean
'Usage
Dim instance As LoginForms
Dim username As String
Dim password As String
Dim returnValue As Boolean

returnValue = instance.Login(username, _
    password)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/LoginForms/Login", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public bool Login(
    string username,
    string password
)

Parameters

  • password
    Type: System.String

    Password for the Project Server user.

Return value

Type: System.Boolean
Returns true for a successful logon to Project Server.

Remarks

After a successful logon, set the CookieContainer property to the user's Project Server credentials for other PSI Web service objects in the same application.

For information about developing ASMX-based applications in a multi-authentication (claims- and Forms-based) environment, see Prerequisites for ASMX-based code samples in Project 2013.

Examples

The LogonPS method in the following example handles logon and the LogoffPS method handles logoff for Project Server authentication.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace LoginDemo
{
    class LoginUtils
    {
        const string LOGINWINDOWS = "_vti_bin/PSI/LoginWindows.asmx";
        const string LOGINFORMS = "_vti_bin/PSI/LoginForms.asmx";

        private static SvcLoginWindows.LoginWindows loginWindows =
            new SvcLoginWindows.LoginWindows();
        private static SvcLoginForms.LoginForms loginForms =
            new SvcLoginForms.LoginForms();
        private CookieContainer cookies = new CookieContainer();

        private string baseUrl; // Example: https://ServerName/ProjectServer/

        public LoginUtils()
        {
        }

        public string BaseUrl
        {
            get
            {
                return baseUrl;
            }
        }

        public CookieContainer Cookies
        {
            get
            {
                return loginForms.CookieContainer;
            }
        }

        // Log on Project Server.
        // Returns true for successful logon.
        public bool LogonPS(bool useWinLogon, string bUrl,
            string userName, string password)
        {
            bool logonSucceeded = false;
            baseUrl = bUrl;

            if (useWinLogon)
            {
                loginWindows.Url = baseUrl + LOGINWINDOWS;
                loginWindows.Credentials = CredentialCache.DefaultCredentials;

                if (loginWindows.Login()) logonSucceeded = true;
            }
            else  // Use LoginForms
            {
                loginForms.Url = baseUrl + LOGINFORMS;
                loginForms.CookieContainer = cookies;

                if (loginForms.Login(userName, password)) logonSucceeded = true;
            }
            return logonSucceeded;
        }

        // Log off Project Server.
        // Returns true for successful logoff.
        public bool LogoffPS(bool useWinLogon)
        {
            bool loggedOff = true;
            if (useWinLogon)
            {
                loginWindows.Logoff();
            }
            else
            {
                loginForms.Logoff();
            }
            return loggedOff;
        }
    }
}

The following code instantiates and uses the LoginUtils class. The project object is an example that shows how to add the user context for a PSI Web service.

private bool windowsAuth = false;  // Use Project Server authentication
private string baseUrl; // Example: https://ServerName/ProjectServerName/ 
private const string PROJECTWEBSERVICE = "_vti_bin/PSI/Project.asmx";

private static LoginUtils loginUtils = new LoginUtils();
public static SvcProject.Project project = 
    new SvcProject.Project();
. . .
// Add the URL, and the user credentials or logon cookie to each PSI Web service object.
public void AddContextInfo(string baseUrl)
{
    // Add the Url property first.
    project.Url = baseUrl + PROJECTWEBSERVICE;

    if (windowsAuth)   // Add Windows credentials
    {
        project.Credentials = CredentialCache.DefaultCredentials;
    }
    else            // Add Project Server logon cookie
    {
        project.CookieContainer = loginUtils.Cookies;
    }
}

See also

Reference

LoginForms class

LoginForms members

WebSvcLoginForms namespace