ExchangeService.AutodiscoverUrl method (String, AutodiscoverRedirectionUrlValidationCallback)

Initializes the Url property to the Exchange Web Services (EWS) endpoint for a specified email address by calling the Autodiscover service.

Namespace:  Microsoft.Exchange.WebServices.Data
Assembly:  Microsoft.Exchange.WebServices (in Microsoft.Exchange.WebServices.dll)

public void AutodiscoverUrl(
	string emailAddress,
	AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback


Type: System.String

The email address to be used.

Type: Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRedirectionUrlValidationCallback

The callback that is used to validate the redirection URL.


A local failure, such as a blocked redirection or a number of redirections greater than the maximum, caused Autodiscover to stop.


The Autodiscover server returned an error.


An empty value was passed in the emailAddress parameter.

This method allows Autodiscover to follow redirects when an Autodiscover server responds with a 302 Redirect status.

The following example shows how to get the user's EWS URL by using the AutodiscoverUrl(String, AutodiscoverRedirectionUrlValidationCallback) method.

using System.Net;
using System.Security;
using Microsoft.Exchange.WebServices.Data;

static bool RedirectionCallback(string url)
    // Return true if the URL is an HTTPS URL.
    return url.ToLower().StartsWith("https://");

static void GetUsersEwsUrl(string userEmailAddress, SecureString userPassword)
    ExchangeService service = new ExchangeService();

    // Set specific credentials.
    service.Credentials = new NetworkCredential(userEmailAddress, userPassword);

    // Look up the user's EWS endpoint by using Autodiscover.
    service.AutodiscoverUrl(userEmailAddress, RedirectionCallback);

    Console.WriteLine("EWS Endpoint: {0}", service.Url);