Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine Authentication Mode
Message
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01682691
Message ID:
01682694
Views:
27
>>>Hi,
>>>
>>>I want to determine the Authentication mode set in the web.config of an ASP.NET application.
>>>
>>>I found this article:
>>>https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.authenticationsection.mode?redirectedfrom=MSDN&view=netframework-4.8#System_Web_Configuration_AuthenticationSection_Mode
>>>
>>>But when I add the following code to my page:
>>>
>>>// Get the current Mode property.
>>>AuthenticationMode currentMode =  authenticationSection.Mode;
>>>
>>>
>>>the line authenticationSection has a squiggly red underling and the error message:
>>>"The name 'authenticationSection' does not exist in the current contect"
>>>
>>>Any suggestion of what I am missing?
>>>
>>>TIA
>>
>>
>> authenticationSection seems to be an object of the type AuthenticationSection and that object has not been created in this code.
>>
>>This might help:
>>
>>// Get the section.
>>AuthenticationSection authenticationSection =
>> (AuthenticationSection)configuration.GetSection(
>> "system.web/authentication");
>
>Thank you for your suggestion.
>
>But if I try the code (Get the section), as you suggested, I get the error on the key work "configuration" and the same message:
>"The name 'configuration' does not exist in the current context"
>
>But I think I found the solution. I replaced the 'configuration' with the ConfigurationManager and now I get no error. And the currentMode has the value Form (which should be in the example I am running). Hopefully I am not missing anything.
>Thank you, again.

Now I get a value in the variable currentMode. When I view this variable in the debugger it shows
System.Web.Configuration.AuthenticationMode.Forms

But I don't know how to use this in the IF statement.

For example,
if (currentMode   .... // I need to determine that it is Forms)
{
    // take action
}
How do I compare the value in currentMode?

UPDATE. Figured the answer. It is:
if (currentMode.Equals(System.Web.Configuration.AuthenticationMode.Forms))
....
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform