Exception with Alternate Mappings

Jan 25, 2012 at 8:04 PM

I am not using the full solutuion. But I am using the same source code for my custom login page.

I have a SharePoint Farm with two servers. When I login to the site that isn't the "default" zone, it is like the Login page wasn't deployed to that site.

I get:

01/25/2012 14:59:36.16 w3wp.exe (0x158C) 0x1BD0 SharePoint Foundation General 8nca Verbose Application error when access /_layouts/OrderTracking/Login.aspx, Error=The given key was not present in the dictionary.   at System.ThrowHelper.ThrowKeyNotFoundException()     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)     at OrderTracking.Layouts.NLBOrderTracking.Login.OnLoad(EventArgs e)     at System.Web.UI.Control.LoadRecursive()     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 2aa6f5aa-9b1e-4af3-be7a-39f4249ad7ca

Any ideas?

Jan 25, 2012 at 9:25 PM

Right here is where the exception is being thrown (on the alternate mapping).

SPIisSettings settings = app.IisSettings[zone];

The Login page IS being deployed to both Servers/WebApps.

 

Jan 25, 2012 at 11:12 PM

 

More info....

When I enumarate:

SPWebApplication.IisSettings I get a single Zone (SPZone) of "Default"

This is true for each of the Web Apps (servers, IIS Instances) that is hit.

Although, one of these is the "Default" and the other, I setup as the "Custom" zone.

This code:

SPAlternateUrl u = app.AlternateUrls[Request.Url];
SPUrlZone zone = u.UrlZone;

works correctly. Depending on which Server the user comes in on, it returns "Default" or "Custom"...

 

 

Mar 19, 2012 at 10:27 AM

You must take closer into your public addresses of your web application. I had public addresses in Default, Internet and Extranet section. This was causing that exception, because eg. using the address from the Internet zone, this code:

SPAlternateUrl u = app.AlternateUrls[Request.Url];
SPUrlZone zone = u.UrlZone;

was returning Internet zone, but I didn't have this zone configured.

When I left only default zone address and configured alternative mappings for default zone with public addresses which I previously had for my zones, everything started to work as expected, because above code started to point to proper zone.

Hope this helps.