Using a colon (:) in a url with ASP.NET/IIS

前端 未结 8 2306
醉话见心
醉话见心 2020-12-05 19:14

I\'m implementing a custom controller in ASP.NET MVC and really want to be able to use a colon in the urls, so that I can identify class/column names and their valu

8条回答
  •  自闭症患者
    2020-12-05 19:47

    Answered similar question here: https://stackoverflow.com/a/12037000/134761

    It seems that ASP.net does not allow colons before the '?' in an URL, even if it is encoded as %3A.

    For example, these won't work:

    http://foo.org/api/persons/foo:bar

    http://foo.org/api/persons/foo%3abar

    But this works:

    http://foo.org/api/persons?id=foo%3abar

    In all examples, we would expect ASP.NET MVC to pass "foo:bar" as an id argument, properly decoded. I just tested this with MVC4 and it seems to work. It is annoying that it doesn't accept the URL encoding before the question mark though, but I'm sure there is a good reason for it. Probably to keep everything before the question mark a valid URL and any arguments after the question mark.

提交回复
热议问题