Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to implement custom configuration in my web apps.
In my web config I have added the following sections:
<configsections>
    <section name="SecurityConfiguration" type="EncryptStringTesting.CustomConfiguration, EncryptStringTesting" /> 
  </configsections>  
  <securityconfiguration>
      <stringencryptdecryptpassword value="" />
 </securityconfiguration>


I've add a new class CustomConfiguration with following code:
Inherits System.Configuration.ConfigurationSection
#Region " Properties "
    <configurationproperty("value",> _
  Public Property value() As String
        Get
            Return CStr(Me("value"))
        End Get
        Set(ByVal value As String)
            Me("value") = value
        End Set
    End Property
    <configurationproperty("stringencryptdecryptpassword",>                          DefaultValue:="", _
                          IsRequired:=True, IsKey:=True)> _
   Public Property StringEncryptDecryptPassword() As String
        Get
            Return CStr(Me("StringEncryptDecryptPassword"))
        End Get
        Set(ByVal value As String)
            Me("StringEncryptDecryptPassword") = value
        End Set
    End Property


In my web page I am try to retrive my custom values:
Dim config As New CustomConfiguration
        config = System.Configuration.ConfigurationManager.GetSection("SecurityConfiguration")
    
        Response.Write(config.StringEncryptDecryptPassword.ToString)

When I call System.Configuration.ConfigurationManager.GetSection("SecurityConfiguration") getting nothing. Could you tell me why?
Posted

Aren't the names case sensitive? You specify "SecurityConfiguration" in the codebehind, but you called it "securityconfiguration" in the xml.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 13-Apr-11 16:03pm    
Added on OP' behalf:

I have changed to SecurityConfiguration in both places but still have the same issue
Manfred Rudolf Bihy 13-Apr-11 16:05pm    
Exactly! 5+
I think OP has the case wrong and the tag "stringencryptdecryptpassword" is most probably also camel cased.
Try putting the code in a try/catch block and see what exception is raised.

BTW, why do you need the value() property?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900