Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

SPUtility.AlternateServerUrlFromHttpRequestUrl method

Returns the outgoing URL for the alternate request URL represented by the specified URI.

Namespace:  Microsoft.SharePoint.Utilities
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
public static Uri AlternateServerUrlFromHttpRequestUrl(
	Uri url
)

Parameters

url
Type: System.Uri

ASystem.Uri object that represents the request URL.

Return value

Type: System.Uri
A System.Uri object that represents the outgoing URL and any additional parts of the URL, such as the path, that together compose the complete incoming URL. For example, if the incoming URL is http://incoming and the outgoing URL is http://outgoing, this method returns http://outgoing. If the incoming URL is http://incoming/sites/mySite/Lists/myList/AllItems.aspx, the returned URI object would represent http://outgoing/sites/mySite/Lists/myList/AllItems.aspx.
If no outgoing URL is defined for the zone associated with the incoming URL, or that incoming URL is not included in a collection of alternate URLs, Microsoft SharePoint Foundation returns the same System.Uri that was passed as parameter to this method.

The following code example uses the AlternateServerUrlFromHttpRequestUrl method to list all the incoming URLs, their matching outgoing URLs, and the URL zone for each alternate request URL implemented on a virtual server.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint.Administration and Microsoft.SharePoint.Utilities namespaces.

SPGlobalAdmin globAdmin = new SPGlobalAdmin();
System.Uri vServerUri = new Uri("http://Server_Name/sites/Site_Name/default.aspx");
SPVirtualServer vServer = globAdmin.OpenVirtualServer(vServerUri);
SPAlternateUrlCollection altUrls = vServer.Config.AlternateUrls;

foreach (SPAlternateUrl url in altUrls)
{
    System.Uri uri = new System.Uri(url.IncomingUrl);
    Response.Write(url.IncomingUrl + " == " + SPUtility.AlternateServerUrlFromHttpRequestUrl(uri) + " == " + url.UrlZone + "<BR>");
}

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.