Atlanta .NET Regular Guys

News

Brendon Schwartz - Email Me
Matt Ranlett - Email Me

Brendon Schwartz

MVP Logo
Community Kit for SharePoint
View Brendon Schwartz's profile on LinkedIn

Matt Ranlett

Matt Ranlett MVP Logo

Community Links

Useful Links

SharePoint 2007

ASP.NET 2.0

Atlanta Area Bloggers

BizTalk

SharePoint 2007 WebControls

SharePoint 2007 Development

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);
}

Comments

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
Leave a Comment

(required) 

(required) 

(optional)

(required)