0

I'm trying to get the timeout value in the following from web.config:

<!-- Majority of xml left out for brevity -->
<configuration>
    <configSections>...</configSections>
    <system.diagnostics>...</system.diagnostics>
    <system.web>
        <authentication mode="Forms">
          <forms timeout="1" /> <!-- Trying to get this value -->
        </authentication>
    </system.web>
</authentication>
</configuration>

I'm using this C# code to start off with. My goal is to first access system.web:

var value = ConfigurationManager.GetSection("configSections"); // null
var value1 = ConfigurationManager.GetSection("system.diagnostics"); // SystemDiagnosticsSection
var value2 = ConfigurationManager.GetSection("system.web"); // null

value and value2 are both null, but value1 is an instance of SystemDiagnosticsSection.

Why can I access system.diagnostics but not system.web?

0

1 Answer 1

0

Thanks to @Yong Shun's comment, I worked it out based on the suggested answer:

var authenticationSection = (AuthenticationSection)ConfigurationManager.GetSection("system.web/authentication");
var timeout = (int)authenticationSection.Forms.Timeout.TotalMinutes;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.