ASP.NET MVC - creating and handling with URLs with Greater Than and Less Than characters
Posted
by pcampbell
on Stack Overflow
See other posts from Stack Overflow
or by pcampbell
Published on 2010-04-09T02:36:21Z
Indexed on
2010/04/09
2:43 UTC
Read the original article
Hit count: 462
Consider a link to a page for a user's profile. A page is creating that URL like this:
//Model.Name has value "<bad guy>"
Html.ActionLink("foo, "ViewUser", new { id=5, title=Url.Encode(Model.Name) })
The actual outcome was
http://mysite/Users/5/%253cbad%2guy%253e
When navigating to that URL, the server generates a HTTP Error 400 - Bad Request.
Question:
Given that the Model.Name
may contain Unicode characters, or characters otherwise illegal in URLs, what's the best way to strip out illegal characters, or otherwise encode them?
The problem surfaces when testing out 'interesting' user inputs with <
and >
, but anything could come from the user, and therefore be put in a URL by way of Model.Name
.
© Stack Overflow or respective owner