Friday 10 July 2009

Alternate Access Mapping Issue

Recently one of my clients started reporting that they were experiencing an intermittent issue where they would randomly receive a HTTP 500 response with the following error:-

[ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +2916027
System.String.Substring(Int32 startIndex) +17
Microsoft.SharePoint.ApplicationRuntime.SPRequestModule.Log(HttpContext context, SPWeb spWeb, Int64 bytes, UInt32 version) +532
Microsoft.SharePoint.ApplicationRuntime.SPRequestModule.PostRequestExecuteHandler(Object oSender, EventArgs ea) +199
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

When reflecting in to the Microsoft.SharePoint dll I could see this was occuring in some code to do with Url.

Looking in the event log on the SharePoint web front ends they were full with multiple copies of the following error:-

Invalid URL: http://www.abc123.com. You may also need to update any alternate access mappings referring to http://abc123.com. Help on this error: http://go.microsoft.com/fwlink/?LinkId=114854

In this environment there are two different hostnames for the SharePoint app (abc123.com and www.abc123.com in this blog post). I took a look at the Alternate Access Mappings and noticed there were two Alternate Accessing Mapping Collections set for the web application. I couldn't work out how this could happen until ServerFault.com helped me out :-)

So it turns out that an External Resource Mapping would cause this to occur.

This was not the case in this environment as I couldn't delete the AAM collection through the UI and running this command:-

stsadm -o deletezoneurl -urlzone Default -resourcename www.abc123.com

resulted in this error...

The IncomingUrl is not present in the collection

The environment was set up as follows:-

1 Web Application running as abc123.com
2 AAM Collections both with one entry for the Default zone (one with abc123.com and the other with www.abc123.com)
1 IIS Website with both hostnames mapped

I knew that this setup was not the standard way to setup two hostnames for one SharePoint Web App. Ideally, there would be one web app (abc123.com) extended to a different zone and assign www.abc123.com to the second zone.

So I carried out the following actions:-

1) Remove the www.abc123.com mapping from the IIS website through IIS Admin on all front end boxes.
2) Ran the following command to remove the AAM collection for www.abc123.com from SharePoint:-

stsadm -o deletezoneurl -urlzone Default -url www.abc123.com

3) Extend the original Web Application in SharePoint to a new zone with hostname www.abc123.com
4) Copied all custom settings from the original website web.config to the new extended website web.config.
5) Copied all custom dlls from the original website bin directory to the new website bin directory

I've got no idea how the system got in this state (before my time! ;-) ) but this stopped all the errors appearing in the event logs and there hasn't been a single complaint about the original problems since!

Hope this helps anyone else experiencing this issue :-)