I need to programmatically determine which zone the current user is accessing a web application through, and was wondering if anyone had any guidance regarding the safest way to determine this.

I understand that you can determine the [`SPUrlZone`][1] from an [`SPAlternateUrl`][2] object, but the MSDN documentation is kind of unclear (surprise, surprise) as to how the indexer by URL works. It says:

> Use an indexer to return a single item from the collection. For example, if the collection is assigned to a variable named myUrls, use myUrls[index] in C# or myUrls(index) in Visual Basic, where index is either the index number of the item in the collection or **a string containing the incoming URL of the request**.

I did find someone's login page code here: [Incorrect authentication method when using Outlook integration][3]

That question uses the following:

    ...
    SPWebApplication app = SPContext.Current.Site.WebApplication;
    SPAlternateUrl u = app.AlternateUrls[Request.Url];
    SPUrlZone zone = u.UrlZone;
    ...

**Is that a safe and consistent way to achieve this?**

**Or are there outlying conditions that could cause this not to function as expected?**

Alternatively, if there are issues with the above, I was thinking this could be achieved somehow by checking properties of each `SPAlternateUrl` iterating through the [`SPWebApplication.AlternateUrls`][4] collection, but obviously that's less ideal than being able to index into the collection directly.


  [1]: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spurlzone.aspx
  [2]: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spalternateurl.aspx
  [3]: http://sharepoint.stackexchange.com/questions/28106/incorrect-authentication-method-when-using-outlook-integration
  [4]: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.alternateurls.aspx