Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8446681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:59:21+00:00 2026-06-10T09:59:21+00:00

Platform: ASP.NET 4.0 MVC 4 C# jQuery Here’s what I want to do. I’m

  • 0

Platform: ASP.NET 4.0 MVC 4 C# jQuery

Here’s what I want to do.

I’m building a simple forum for my product. I want to give users a text area to enter their posts or comments.

  1. I’d like to allow basic text formatting HTML and links – like p, a, b, i
  2. Don’t want any other html styling – i.e. div, span, etc. etc.
  3. Don’t want any scripting access

Is there a clever way to do this? I could, for e.g., allow unsafe text and examine it on the server side but I doubt I’d be able to clean it up correctly and might open security holes.

Preferably want to avoid heavy duty plugins.

Thanks!

(PS – my worst fallback is that I allow safe text only, i.e. keep the ASP.NET security on, and then use a special markup for links – like [link] [b] [i])

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:59:22+00:00Added an answer on June 10, 2026 at 9:59 am

    No matter what approach you use, you need to assume everything entered into the field is malicious, i.e. don’t trust any data.

    I wouldn’t bother too much with any client validation in JavaScript/jQuery. It’ll be complex and only need to be redone server side.

    Server side you want to take a whitelist approach, i.e. if it’s not on the list, it’s invalid. You wouldn’t be able to use a XML processor because the user’s text may not result in valid XML, instead you’d probably want to use a regular expression.

    I would define a set of tags that are valid (you’ve said p, a, b and i but I would be weary of the last two as you’d almost never get them in ‘wild’ html), I would then define if and which attributes are valid for these tags. I’m guessing you’d want at the very least a href on the a.

    You could strip any text within tags that doesn’t match… my regex skills aren’t great, but this appears to find all the tags you want to keep, it needs to be inverted.

    \<a\shref\=".[^\"]*\"\>|\</?[abip]\s?\>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple blogging platform with ASP.NET MVC. My question is regarding forms
Why must IE be so difficult? Building site on ASP.NET MVC platform. Email page
I am looking for forum engine. There are some requirements: platform is ASP.NET(MVC 2,3)
Platform: ASP.NET 4.0, MVC 4 RC, VS 2012 Update: I've answer my question, myself.
I have downloaded the ASP.NET MVC 2 Release version (using Web Platform Installer) as
I'm kind of new to the .NET platform. And currently I'm learning ASP.NET MVC.
I have an ASP.Net MVC page where I want to use AJAX to update
I am developing some REST resources using the ASP.NET MVC 3 platform. So far,
Currently we are migrating an existing asp.net web application to asp.net mvc 2 platform.
I am new to asp.net mvc platform. I'm developing with razor template engine in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.