2

I'm building a tool to be used "in-house" for installation purposes.

It's purpose is to get settings from an xml file (such as Authentication) and apply it on IIS.

Is there a way to check if the Authentication is currently set to forms?

Couldn't find a way to achieve it, just many examples which sets the corresponding XML nodes in the configuration files to enable authentication of the desired type.

Any answer would be appreciated.

1 Answer 1

2

You can use XPath XML queries against config files to look for the <authentication> tag and retrieve its mode attribute value. Better yet, use some existing scripted capability for this. There are Powershell commandlets for IIS. Take a look at the Get-WebConfiguration cmdlet as discussed here. It even has XPath capabilities.

If you want to roll your own XPath query, it would look something like

XmlDocument doc = new XmlDocument();
doc.load("PATH TO A CONFIG FILE HERE");
XmlNode authenticationNode = doc.SelectSingleNode("//system.web/authentication");
//Value of attribute is at
var authenticationMode = authenticationNode.Attributes["mode"].Value;

However this approach does not deal with the fact that IIS composites config files from higher level directories with lower level ones--this just reads on particular file. So you'd have to add some logic to see what authentication is truly in effect at a given folder level.

A better way might be to do reflection on the AppDomain of your web application, read the config that way and then check the value.

Or you try this from MSDN documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.