Skip to main content
replaced http://sharepoint.stackexchange.com/ with https://sharepoint.stackexchange.com/
Source Link

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 from an SPAlternateUrl 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 integrationIncorrect authentication method when using Outlook integration

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 collection, but obviously that's less ideal than being able to index into the collection directly.

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 from an SPAlternateUrl 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

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 collection, but obviously that's less ideal than being able to index into the collection directly.

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 from an SPAlternateUrl 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

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 collection, but obviously that's less ideal than being able to index into the collection directly.

Rollback to Revision 1
Source Link
RJ Cuthbertson
  • 8.4k
  • 6
  • 38
  • 76

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]SPUrlZone from an [SPAlternateUrl][2]SPAlternateUrl 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]Incorrect authentication method when using Outlook integration

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]SPWebApplication.AlternateUrls collection, but obviously that's less ideal than being able to index into the collection directly. cactus [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

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. cactus [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

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 from an SPAlternateUrl 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

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 collection, but obviously that's less ideal than being able to index into the collection directly.

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[SPUrlZone][1] from an SPAlternateUrl[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[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[SPWebApplication.AlternateUrls][4] collection, but obviously that's less ideal than being able to index into the collection directly. cactus [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

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 from an SPAlternateUrl 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

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 collection, but obviously that's less ideal than being able to index into the collection directly.

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. cactus [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

Source Link
RJ Cuthbertson
  • 8.4k
  • 6
  • 38
  • 76
Loading