I'm currently using System.DirectoryServices.DirectoryEntry and the 'AuthFlags' property therein to set Anonymous access to a virtual web. To enable anonymous access I give it a value of 1. What value do I need to set to enable forms auth?
I have this idea in the back of my head that maybe this is only set via the web.config?
I notice you're using
System.DirectoryServices
to configure these features on IIS7 (according to your tags).In IIS7 you can configure both of these settings using the
Microsoft.Web.Administration
library instead:Setting the authentication type (replaces
AuthFlags
):To configure Forms Authentication:
The code above will create a new
web.config
file in the root of the website or modify an existing one.To use
Microsoft.Web.Administration
, add a reference toC:\Windows\System32\InetSrv\Microsoft.Web.Administration.dll
.Source
I would recommend a slightly different approach if maintaining IIS 7 or 7.5. The concepts are similar but de-emphasizing the ASP.Net oriented <system.web> in the local application web.config in trade for emphasizing the IIS oriented <system.webServer> in the server applicationHost.config.
Start at the bottom of this link and scroll up... http://www.iis.net/ConfigReference/system.webServer/security/authentication/windowsAuthentication
The core approach is to make changes in IIS Manager and observe how the application host config changes for that application. Then you replicate those changes by driving the new Microsoft.Web.Administration assembly appropriately.
Location: %systemroot%\system32\inetsrv\config\applicationHost.config
Things to look for: