Why does StringValidator always fail for custom configuration section?

后端 未结 4 1638
一整个雨季
一整个雨季 2021-02-19 09:41

I have created a custom configuration section in a c# class library by inheriting from ConfigurationSection. I reference the class library in my web application (a

4条回答
  •  半阙折子戏
    2021-02-19 10:31

    The resolving of the StringValidator can be done by any one of the following:

    • Removing MinLength argument
    • Setting MinLength = 0
    • Removing the StringValidator Attribute
    • Adding DefaultValue to the ConfigurationProperty Attribute

    The Ideal definition for the property is like:

    [ConfigurationProperty("title", IsRequired = true, DefaultValue = "something")]
    [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;’\"|\\"
      , MinLength = 1
      , MaxLength = 256)]
    public string Title
    {
        get { return this["title"] as string; }
        set { this["title"] = value; }
    }
    

提交回复
热议问题