SPWeb.AuthenticationMode always returns WindowsAuthentication
I am trying to determine what type of authentication the current SharePoint 2007 web site has, but no matter which SharePoint site I checked the AuthenticationMode of the SPWeb always seems to return WindowsAuthentication. The site that I am using is set up with Forms Based Authentication (FBA), and I would think that SharePoint object model would know the current authentication mode should be AuthenticationMode.Forms, but it doesn't.
I am not sure if I am just missing something? Maybe you really do have to go to the WebApplication and the IISSettings to get the actual value. Seems like a long way to go to get what you need. Keep in mind that to get the IISSettings you will also need to know which zone the site is. Using the Alternate URLs this can be done with the URL of the site.
Let me know if you have a better way. For now it looks like this might be a clean way to get what you want. You can also use the current SPWeb instead of hardcoding it, but this is easier for Console Apps and to make it more clear.
using (SPSite spSite = new SPSite(@"http://fba.devcow.com"))
{
SPWeb spweb = spSite.RootWeb;
SPWebApplication webApp = spweb.Site.WebApplication;
SPAlternateUrl altURL = webApp.AlternateUrls[spweb.Url];
SPIisSettings iisSettings = webApp.IisSettings[altURL.UrlZone];
Console.WriteLine(iisSettings.AuthenticationMode);
}