1

my web.config contains sections like

location -- system.web -- authorization -- allow

<location path="ClientDisabled.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

(I am not sure how to write full tag including XML tags here, seems like forum is not allowing it)

I and several others under main node. I need to read them via configuration manager. I am trying, but I am unable to read them using code like

WebConfigurationManager.GetSection ("location", "~/")

or other many possiblities. I am not sure even if I can read these entries via Configuration Manager.

Is there someone who knows how can I read them and write back, when needed? I guess if I can read them, I might need to delete one or two such entries and then save back web.config file.

thanks for the help. Sameers

Sameers Javed
  • 342
  • 2
  • 5
  • 16
  • Take a look at this http://stackoverflow.com/questions/18361909/how-can-i-add-and-remove-authorised-users-from-web-config-in-asp-net – Cherian M Paul Aug 22 '13 at 14:11

1 Answers1

0

ah! i found it. Its Locations property of Configuration. So u can use it like

Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("~")
    For temp As Integer = config.Locations.Count - 1 To 0 Step -1
        Dim loc As ConfigurationLocation = config.Locations(temp)
        If loc.Path.ToLower.Contains("MyAccount".ToLower) Then
            location found here
        Else
            location not found
        End If
    Next

However, I dont see if I can save that back to web.config after doing some changes etc. Someone knows how to save that back? thanks, Sameers

Sameers Javed
  • 342
  • 2
  • 5
  • 16