Welcome to Atlanta .NET Regular Guys Sign in | Join | Help

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];

Published 05-09-2007 05:00 by Brendon Schwartz
Filed Under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



guy said:

if have the same problem.
i searched in google and i found some article that check the authenticationmode with spsecurity object and that's working fine for me.
October 15, 2007 12:18 AM

What do you think?


About Brendon Schwartz

Brendon Schwartz has worked in the Atlanta area User Group scene and is known around town as one of the Atlanta .Net Regular Guys (www.devcow.com). He is currently on the INETA Board of Directors as the Vice President of Technology and is a Microsoft MVP for ASP.NET. Today, Brendon works to solve real world business problems with Microsoft technologies, such as SharePoint, Office, BizTalk, VSTS, and .NET technologies. In addition to presenting at local user groups, he helped create the Free Training 1,2,3! series (www.freetraining123.com) to help developers learn Microsoft technologies. He presented material at the first SharePoint 1,2,3! event (www.sharepoint123.com) along with other members of the Atlanta Microsoft Professionals. Brendon has helped on the leadership teams of five different user groups, and has been interviewed for his community efforts on Pod Casts - including the ASP.NET Pod Cast, .NET Rocks! (Carl Franklin Road Show - Atlanta) and the SharePoint Show Pod Cast. At the first Atlanta Code Camp in 2005, he presented material on ASP.NET mobile controls.
Powered by Community Server, by Telligent Systems