.NET Uri class query missing the semicolon reserved character, simple workarounds?
This https://msdn.microsoft.com/en-us/library/system.uri.query.aspx and this https://ietf.org/rfc/rfc1738.txt suggest that the .Net Uri class does not recognize the semicolon as an acceptable character to represent a query in a URL.
This only requires one line or so to workaround, but I like my code clean. If there is a solution that allows me to not do string parsing myself outside the .Net set of Uri classes, I'd pre开发者_Python百科fer that. Is there any existing .Net code that handles semicolons for recognizing them as part of a query in a URL?
RFC 3986 agrees with RFC 1738 (which it updates) in defining the query as a portion following a question mark (?
), and in stating that a semicolon can be used to separate parameter-value pairs "applicable to that segment".
In a prospero URI (the only case given in RFC 1738 where a semicolon is shown used) semicolons indicate a parameter and parameter value in the path of the URI - not a query.
HTTP URIs do have semicolons used in their queries, but only after the ?
, e.g. http://example.net/search?q=something;page=2
. Unfortunately actual usage has never quite replaced the &
character for this function and it is poorly supported by server-side code (including ASP.NET) which limits the ability of client-side code to adopt it (pretty much no browser does).
Still, In such cases the .NET Uri object correctly identifies only that portion following the ?
as a query, including semicolons if present. Its behaviour is correct.
精彩评论