ExchangeService.AutodiscoverUrl Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
AutodiscoverUrl(String) |
Initializes the Url property to the Exchange Web Services (EWS) endpoint for a specified email address by calling the Autodiscover service. |
AutodiscoverUrl(String, AutodiscoverRedirectionUrlValidationCallback) |
Initializes the Url property to the Exchange Web Services (EWS) endpoint for a specified email address by calling the Autodiscover service. |
AutodiscoverUrl(String)
Initializes the Url property to the Exchange Web Services (EWS) endpoint for a specified email address by calling the Autodiscover service.
public:
void AutodiscoverUrl(System::String ^ emailAddress);
public void AutodiscoverUrl (string emailAddress);
Public Sub AutodiscoverUrl (emailAddress As String)
Parameters
- emailAddress
- String
The email address to be used.
Exceptions
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.
Examples
The following example shows how to get the user's EWS URL by using the AutodiscoverUrl(String) method.
using System.Net;
using System.Security;
using Microsoft.Exchange.WebServices.Data;
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);
Console.WriteLine("EWS Endpoint: {0}", service.Url);
}
Remarks
If an Autodiscover server returns a redirect HTTP status code, this method will generate an AutodiscoverLocalException with the Message property set to a string such as "Autodiscover blocked a potentially insecure redirection to https://autodiscover.contoso.com/autodiscover/autodiscover.xml. To allow Autodiscover to follow the redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload." This exception is generated for all redirect responses, regardless of the validity of the URL returned in the redirect response.
To enable redirection, use the AutodiscoverUrl(String, AutodiscoverRedirectionUrlValidationCallback) overload instead.
Applies to
AutodiscoverUrl(String, AutodiscoverRedirectionUrlValidationCallback)
Initializes the Url property to the Exchange Web Services (EWS) endpoint for a specified email address by calling the Autodiscover service.
public:
void AutodiscoverUrl(System::String ^ emailAddress, Microsoft::Exchange::WebServices::Autodiscover::AutodiscoverRedirectionUrlValidationCallback ^ validateRedirectionUrlCallback);
public void AutodiscoverUrl (string emailAddress, Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback);
Public Sub AutodiscoverUrl (emailAddress As String, validateRedirectionUrlCallback As AutodiscoverRedirectionUrlValidationCallback)
Parameters
- emailAddress
- String
The email address to be used.
- validateRedirectionUrlCallback
- AutodiscoverRedirectionUrlValidationCallback
The callback that is used to validate the redirection URL.
Exceptions
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.
Examples
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);
}
Remarks
This method allows Autodiscover to follow redirects when an Autodiscover server responds with a 302 Redirect status.