How to Remove HTML in ASP.NET

The ASP.NET computer programming language lets developers easily deploy their applications in a variety of ways. Hypertext Markup Language (HTML), among the most frequently used programming tools for website builders, is supported by ASP.NET. If you have experience with programming language and need to remove HTML from ASP.NET, follow a few straightforward steps.

Things You'll Need

  • Internet connection
Show More

Instructions

    • 1

      Evaluate the coding structure of your website. Determine if it is acceptable to strip some of the existing HTML codes and replace them with regular expression string. HTML is useful in designing web contents, but it can destroy the website's layout, especially when it involves JavaScript or embedded style sheet.

    • 2

      Paste the following public static string to strip the HTML tags that are not necessary, or considered as harmful tags:

      public static string StripHtml(string html, bool allowHarmlessTags)

      {

      if (html == null || html == string.Empty)

      return string.Empty;

      if (allowHarmlessTags)

      return System.Text.RegularExpressions.Regex.Replace(html, "", string.Empty);

      return System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);

      }

      This string in ASP.NET can also be set to remove or allow harmful tags by assigning a boolean flag that determines which tags are allowed. You can even add more harmful tags to this static expression just as long as they don't ruin the design or layout of your website.

    • 3

      Disable the HTML tags if you want to keep them in your programming text by utilizing the Replace () function in ASP.NET. Since the SCRIPT tags are the most damaging component of HTML, you can disable all of them in the programming text by posting the following string:

      strText = Replace(strText, "<script", "<script", 1, -1, 1)

      If you still feel unsafe with this solution, you can disable all the HTML tags with this expression:

      strText = Replace(strText, "<", "<")

    • 4

      Run the strings to see the results by displaying the website on your browser. If it looks fine, view your source code by right-clicking your Web page and selecting "View page source" in Google Chrome or "View source" in Internet Explorer. You can now remove the disabled text of the HTML tags because they are no longer needed and could cause confusion for other viewers of your website.

Tips & Warnings

  • Do not modify any tags in your programming code if you are not certain what the results will be. Modifying the tags can mess up the structure or design of your website.

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured