0

I'd like to add some kind of simple URL resolution and formatting to my C# and jQuery-based ASP.NET web application. I currently allow users to add simple text-based descriptions to items and leave simple comments ('simple' as in I only allow plain text).

What I need to support is the ability for a user to enter something like:

Check out this cool link: http://www.really-cool-site.com

...and have the URL above properly resolved as a link and automagically turned into a clickable link...kinda like the way the editor in StackOverflow works. Except that we don't want to support BBCode or any of its variants. The user experience would actually be more like the way Facebook resolves user-generated URL's.

What are some jQuery + C# solutions I should consider?

6
  • 6
    Linkify? Commented Aug 18, 2011 at 7:37
  • 3
    @bzlm please make this an answer! ... Commented Aug 18, 2011 at 7:38
  • possible duplicate of C# code to linkify urls in a string Commented Aug 18, 2011 at 7:40
  • Or jQuery Text to Link Script? Commented Aug 18, 2011 at 7:49
  • Reviewing all the referenced links from above. Thanks in advance. Commented Aug 18, 2011 at 8:01

2 Answers 2

0

There's another question with a solution that might help you. It uses a regex in pure JS.

Personally though, I would do it server-side when the user submits it. That way, you only need to do it once, rather than every time you display that text. You could use a similar regex in C#.

Sign up to request clarification or add additional context in comments.

2 Comments

Lots of good information in the linked question. Digging through it now. I always assumed I'd need a solution that used a combination of jQuery + some kind of managed code DLL on the server to really clean up the URL. Aren't the client-side only solutions vulnerable to hacks?
If all it does is turn text links into anchor tag links, all that can be "hacked" is that users would be able to post links to anything they like, and then those links would (presumably?) be viewable by other users. It wouldn't open up any security vulnerabilities on your server, as the server-client interface won't have changed. Users can, of course, fiddle around with the script that runs on the page, but this will only affect them, not other users.
0

I ended up using server-side C# code to do the linkification. I use an AJAX-jQuery wrapper to call into a PageMethod that does the work.

The PageMethod both linkifies and sanitizes the user-supplied string, then returns the result.

I use the Microsoft Anti-Cross Site Scripting Library (AntiXSS) to sanitize:

http://www.microsoft.com/download/en/details.aspx?id=5242

And I use C# code I found here and there to resolve and shorten links using good olde string parsing and regular expressions.

My method is not as cool as the way FaceBook does it in real time, but at least now my users can add links to their descriptions and comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.