0
votes

I have some code in a SharePoint page that is attempting to get the provider information for the currently used Web App and Zone.

This code finds the zone name correctly:

SPWebApplication app = SPContext.Current.Site.WebApplication;
SPAlternateUrl u = app.AlternateUrls[Request.Url];
SPUrlZone zone = u.UrlZone;

The zone comes back "Custom" or "Default", depending on which URL/Server is used.

Next, I try to get the IIS Settings for that zone using the code below:

SPIisSettings settings = app.IisSettings[zone];

I get an exception when testing the "Custom" site/URL (AAM). It seems that no matter what URL/Server I access the site from, app.IisSettings[] only contains a "key" for "Default".

What am I missing?

Shayne

1

1 Answers

0
votes

Try using:

SPWebApplication iisApp = SPWebApplication.Lookup(Request.Url);
SPIisSettings settings = iisApp.IisSettings[zone];

To get the IisSettings for a different zone. As the SPContext might be returning you the Default IIS web app.