iis 7 - Programmatically enable forms authentication in IIS 7.0 -


i'm using system.directoryservices.directoryentry , 'authflags' property therein set anonymous access virtual web. enable anonymous access give value of 1. value need set enable forms auth?

i have idea in of head maybe set via web.config?

i notice you're using system.directoryservices configure these features on iis7 (according tags).

in iis7 can configure both of these settings using microsoft.web.administration library instead:

setting authentication type (replaces authflags):

iis 7 configuration: security authentication <authentication>

to configure forms authentication:

using microsoft.web.administration;    ... long iisnumber = 1234; using(servermanager servermanager = new servermanager()) {   site site = servermanager.sites.where(s => s.id == iisnumber).single();    configuration config = servermanager.getwebconfiguration(site.name);   configurationsection authenticationsection =                 config.getsection("system.web/authentication");   authenticationsection.setattributevalue("mode", "forms");    configurationsection authorizationsection =                 config.getsection("system.web/authorization");   configurationelementcollection addordenycollection =                 authorizationsection.getcollection();   configurationelement allowelement = addordenycollection.createelement("allow");   allowelement["users"] = "?";    addordenycollection.add(allowelement);   servermanager.commitchanges(); } 

the code above create new web.config file in root of website or modify existing one.

to use microsoft.web.administration, add reference c:\windows\system32\inetsrv\microsoft.web.administration.dll.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -