title: How to whitelist html tags in Asp.net ValidationAttribute
body: <p>I'm using Asp.net "ValidationAttribute" to validate user input, Currently i throw error if user enters any html tags like <code>&lt;html&gt;,&lt;h1&gt;,&lt;div&gt;</code> etc etc but i want to whitelist few tags and do not want to throw error if user enters input with some tags like following should not fail.</p>
  
  <pre><code>&lt;strong&gt; hello world &lt;/strong&gt;
  &lt;p&gt;hello &lt;/p&gt;
  </code></pre>
  
  <p>but the following should fail since it's <code>div</code> not in whitelist tags array above</p>
  
  <pre><code>&lt;div&gt;hello&lt;/div&gt; 
  </code></pre>
  
  <p>Current implementation:</p>
  
  <pre><code>public sealed class WhiteListAttribute : ValidationAttribute
  {
      public static bool EnableWhiteListTags { get; set; }
      private static string[] whitelistTags = new[] { "strong" };
  
      protected override ValidationResult IsValid(object value, ValidationContext validationContext)
      {
          string str = (string)value;
  
          if (str != null &amp;&amp; 
              !EnableWhiteListTags &amp;&amp;
              !RequestValidator.Current.InvokeIsValidRequestString(null, str, RequestValidationSource.Form, null, out int index))
          {
              return new ValidationResult($"A potentially dangerous value was detected from request {validationContext.Name}: {str}");
          }
  
          return ValidationResult.Success;
      }
  }
  </code></pre>
  
  <p>How can i allow user to enter only specific html tags which i defined in my array <code>private static string[] whitelistTags = new[] { "strong" };</code>, so let's say if user enters any text which has html (<code>&lt;strong&gt;</code>) tag , validation should not fail but if user enters any other text with html tags like (<code>&lt;div&gt;, &lt;p&gt;</code>) etc , it should fail as it does currently</p>