locked
How to set authentication with appcmd.exe or ServerManager RRS feed

  • Question

  • User1955189366 posted

    I'd like to set the authentication mode for a web site programaticly, can I do this by calling appcmd.exe with some nifty inparameters or using the Microsoft.Web.Administration.ServerManager object? (RawAttributes?)

    By authentication mode I mean anonymous, basic (clear text) or windows integrated. I've searched msdn but fail to find any information on this!.

    Thanks for any help! 

    Monday, September 17, 2007 3:02 AM

Answers

  • User989702501 posted

    For appcmd, you can set it via /section:xxxx. all auth schemes are locked except Form, so you either unlock it first or commit it at apphost level (meaning store the config in applicationHost.config, which is not so good as in xcopy deployment via web.config file.

    Example.
    appcmd set config "default web site" /section:windowsAuthentication /enabled:true /commit:apphost

    or unlock first:
    appcmd unlock config /section:windowsAuthentication
    appcmd set config "default web site" /section:windowsAuthentication /enabled:true

     

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, September 17, 2007 4:22 AM
  • User1073881637 posted

    You should post your question in IIS7 - Extensibility.   http://forums.iis.net/1042.aspx 

    I would be interested in the answer also, I tried a few tries and kept bumping up against an index error.  Here is my code sample.  I manually set it in the GUI to see what the value stored in the applicationHost.config.    Here is what is stored.

        <location path="Default Web Site">
            <system.webServer>
                <security>
                    <authentication>
                        <basicAuthentication enabled="true" />
                    </authentication>
                </security>
            </system.webServer>
        </location>

    Here is my code sample.

    Dim objAuth As New Microsoft.Web.Administration.ServerManager
    objAuth.Sites(
    "Default Web Site").SetAttributeValue("basicAuthentication", False)
    objAuth.CommitChanges()

    This lists various commands in appcmd
    appcmd list sites -config -?

    C:\Windows\System32\inetsrv>appcmd list sites -config -?
    ERROR ( message:-name
    -id
    -serverAutoStart
    -bindings.[protocol='string',bindingInformation='string'].protocol
    -bindings.[protocol='string',bindingInformation='string'].bindingInformation
    -limits.maxBandwidth
    -limits.maxConnections
    -limits.connectionTimeout
    -logFile.logExtFileFlags
    -logFile.customLogPluginClsid
    -logFile.logFormat
    -logFile.directory
    -logFile.period
    -logFile.truncateSize
    -logFile.localTimeRollover
    -logFile.enabled
    -traceFailedRequestsLogging.enabled
    -traceFailedRequestsLogging.directory
    -traceFailedRequestsLogging.maxLogFiles
    -applicationDefaults.path
    -applicationDefaults.applicationPool
    -applicationDefaults.enabledProtocols
    -virtualDirectoryDefaults.path
    -virtualDirectoryDefaults.physicalPath
    -virtualDirectoryDefaults.userName
    -virtualDirectoryDefaults.password
    -virtualDirectoryDefaults.logonMethod
    -virtualDirectoryDefaults.allowSubDirConfig
    -[path='string'].path
    -[path='string'].applicationPool
    -[path='string'].enabledProtocols
    -[path='string'].virtualDirectoryDefaults.path
    -[path='string'].virtualDirectoryDefaults.physicalPath
    -[path='string'].virtualDirectoryDefaults.userName
    -[path='string'].virtualDirectoryDefaults.password
    -[path='string'].virtualDirectoryDefaults.logonMethod
    -[path='string'].virtualDirectoryDefaults.allowSubDirConfig
    -[path='string'].[path='string'].path
    -[path='string'].[path='string'].physicalPath
    -[path='string'].[path='string'].userName
    -[path='string'].[path='string'].password
    -[path='string'].[path='string'].logonMethod
    -[path='string'].[path='string'].allowSubDirConfig
     )

     

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, September 17, 2007 5:05 AM

All replies

  • User989702501 posted

    For appcmd, you can set it via /section:xxxx. all auth schemes are locked except Form, so you either unlock it first or commit it at apphost level (meaning store the config in applicationHost.config, which is not so good as in xcopy deployment via web.config file.

    Example.
    appcmd set config "default web site" /section:windowsAuthentication /enabled:true /commit:apphost

    or unlock first:
    appcmd unlock config /section:windowsAuthentication
    appcmd set config "default web site" /section:windowsAuthentication /enabled:true

     

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, September 17, 2007 4:22 AM
  • User1073881637 posted

    You should post your question in IIS7 - Extensibility.   http://forums.iis.net/1042.aspx 

    I would be interested in the answer also, I tried a few tries and kept bumping up against an index error.  Here is my code sample.  I manually set it in the GUI to see what the value stored in the applicationHost.config.    Here is what is stored.

        <location path="Default Web Site">
            <system.webServer>
                <security>
                    <authentication>
                        <basicAuthentication enabled="true" />
                    </authentication>
                </security>
            </system.webServer>
        </location>

    Here is my code sample.

    Dim objAuth As New Microsoft.Web.Administration.ServerManager
    objAuth.Sites(
    "Default Web Site").SetAttributeValue("basicAuthentication", False)
    objAuth.CommitChanges()

    This lists various commands in appcmd
    appcmd list sites -config -?

    C:\Windows\System32\inetsrv>appcmd list sites -config -?
    ERROR ( message:-name
    -id
    -serverAutoStart
    -bindings.[protocol='string',bindingInformation='string'].protocol
    -bindings.[protocol='string',bindingInformation='string'].bindingInformation
    -limits.maxBandwidth
    -limits.maxConnections
    -limits.connectionTimeout
    -logFile.logExtFileFlags
    -logFile.customLogPluginClsid
    -logFile.logFormat
    -logFile.directory
    -logFile.period
    -logFile.truncateSize
    -logFile.localTimeRollover
    -logFile.enabled
    -traceFailedRequestsLogging.enabled
    -traceFailedRequestsLogging.directory
    -traceFailedRequestsLogging.maxLogFiles
    -applicationDefaults.path
    -applicationDefaults.applicationPool
    -applicationDefaults.enabledProtocols
    -virtualDirectoryDefaults.path
    -virtualDirectoryDefaults.physicalPath
    -virtualDirectoryDefaults.userName
    -virtualDirectoryDefaults.password
    -virtualDirectoryDefaults.logonMethod
    -virtualDirectoryDefaults.allowSubDirConfig
    -[path='string'].path
    -[path='string'].applicationPool
    -[path='string'].enabledProtocols
    -[path='string'].virtualDirectoryDefaults.path
    -[path='string'].virtualDirectoryDefaults.physicalPath
    -[path='string'].virtualDirectoryDefaults.userName
    -[path='string'].virtualDirectoryDefaults.password
    -[path='string'].virtualDirectoryDefaults.logonMethod
    -[path='string'].virtualDirectoryDefaults.allowSubDirConfig
    -[path='string'].[path='string'].path
    -[path='string'].[path='string'].physicalPath
    -[path='string'].[path='string'].userName
    -[path='string'].[path='string'].password
    -[path='string'].[path='string'].logonMethod
    -[path='string'].[path='string'].allowSubDirConfig
     )

     

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, September 17, 2007 5:05 AM
  • User1073881637 posted

    Hehe.  While was working on the code side, I see Bernard posted the appcmd syntax, excellent.  I still would be curious via code how it would be done. 

    Monday, September 17, 2007 5:08 AM