Partilhar via


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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Shared Function AlternateServerUrlFromHttpRequestUrl ( _
    url As Uri _
) As Uri
'Usage
Dim url As Uri
Dim returnValue As Uri

returnValue = SPUtility.AlternateServerUrlFromHttpRequestUrl(url)
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.

Examples

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.

Dim globAdmin As New SPGlobalAdmin()Dim vServerUri = New Uri("
http://Server_Name/sites/Site_Name/default.aspx
")Dim vServer As SPVirtualServer = globAdmin.OpenVirtualServer(vServerUri)Dim altUrls As SPAlternateUrlCollection = vServer.Config.AlternateUrlsDim url As SPAlternateUrlFor Each url In  altUrls    Dim uri As New System.Uri(url.IncomingUrl)    Response.Write((url.IncomingUrl + " == " + SPUtility.AlternateServerUrlFromHttpRequestUrl(uri) + " == " + url.UrlZone + "<BR>"))Next url
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>");
}

See Also

Reference

SPUtility Class

SPUtility Members

Microsoft.SharePoint.Utilities Namespace