0

In my Web.Config file I have the following:

<system.webServer>
  <handlers>
    <add name="HANDLERNAME" verb="*" path="PATH.axd" type="HANDLERTYPE">
  </handlers>
</system.webServer>

Before I run a particular bit of code, I want to check to see if the handler is present in my Web.Config file.

Is this something I'm able to do?

I've tried: ConfigurationManager.GetSection("system.webServer/handlers") with no success, as this returns null.

Any help would be greatly appreciated!

2

1 Answer 1

1

I found two ways to check for the Handlers in the web.config

    XmlDocument doc = new XmlDocument();
    doc.Load(path); *//path is the location of the web.config file*

    XmlElement root = doc.DocumentElement;
    XmlNode nodes = root.SelectSingleNode("/system.webServer");
    XmlNodeList childnotes = nodes.ChildNodes;
    bool isExist = false;;
    foreach (XmlNode node in childnotes)
    {
        if (node.Name.Contains("handlers"))
        {
            isExist = node.OuterXml.Contains("HANDLERNAME");
        }
    }

you can check the value of isExist

The other way is to get the entire web.config as a string and check if it contains HANDLERNAME

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.