views:

1510

answers:

4

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 values, like so:

http://mysite.com/user:chaiguy

...but apparently ASP.NET or IIS doesn't allow colons in urls. I did some digging and apparently it's considered a security issue, but, I'm using MVC and am handling all url paths manually (just treating them as strings), and not relating them to the file system, so I'm pretty sure this doesn't apply.

I also heard some talk about implementing a custom Http handler or something.

Any thoughts or ideas would be much appreciated.

+4  A: 

I suggest you rethink what you want to do. Use pathing to indicate context and hide your class and field names, mapping particular contexts within your URL paths to class names and fields. If you need to indicate a user, for example, build your URL layout like mysite.com/users/chaiguy rather than mysite.com/user:chaiguy.

Randolpho
I realize that's an option and appreciate the suggestion, but I'm really keen on doing it this way. If I can't use a colon, I will likely end up using a different symbol, but a colon would be ideal.
chaiguy
Er.... why? Seriously, why break standards?
Randolpho
Because what I want to do is very different, and involves url-based interaction with a non-web system.
chaiguy
I suggest, then, that you investigate building a web service. WCF is a nice technology for that, and it hosts well in IIS.
Randolpho
A: 

Er.... why? Seriously, why break standards? – Randolpho

...

I suggest, then, that you investigate building a web service. WCF is a nice technology for that, and it hosts well in IIS.

I happen to like urls, and WCF is way too complicated for my purposes. I want it to be url-compatible, like REST, but capable of more than just navigating hierarchies, or doing well laid-out things. The problem I have with /users/chaiguy is that it is interpreting hierarchy where there is none: in my system "user" is a class, it's not a folder. user:chaiguy means the instance of the user class with the value of "chaiguy", and that is a single entity, that has the potential of having child-entities. So for example:

/user:chaiguy/name

...I would like to display the name of that entity. If I did this with your method, it would look like this:

/users/chaiguy/name

The problem is how do you know what's the class and what's the value? It could be interpreted as

/users/chaiguy:name

in my system, and that doesn't make sense. See what I'm getting at? To give a slightly more complicated example, suppose we want to select a child of the user entity out of multiple instances. So a user might have several email addresses. To select one, we might use:

/user:chaiguy/email:[email protected]/

So it is in fact recursive. It's not a file path, it's more like an XPath (or maybe similar to jQuery based on what little I know of it yet). That is, it's more of a dynamically-evaluated query selection than a hardwired file path. It gets evaluated on the server.

Make no mistake, I'm not building a typical web site or even web service here.

chaiguy
I should also add it's all very experimental at this point. I'm not saying things won't change.
chaiguy
Well, I don't think you're going to be able to do what you want to do. It's time to hit the drawing board.
Randolpho
That said, if you insist on mapping classes and field names in your URLs (which I highly recommend against), then you could just do alternating paths: mysite.com/user/chaiguy/email/[email protected]/.
Randolpho
Randolpho
+1  A: 

Try setting HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters\AllowRestrictedChars. This is from http://support.microsoft.com/?id=820129. I don't know whether ASP.NET/MVC does some checking on their own but if it's only http.sys blocking you, this should fix it.

Sriram Krishnan
Is the colon even valid in a URL at that point? If not, then just don't do this, as http.sys will not be the only piece of software that won't like it.
John Saunders
A: 

Actually there is WCF REST available, and you can easily get up and running within an hour by using the WCF Starter Kit available here. This takes the power of REST and merges it with the ease of WCF. Also with WCF you can also create your own transport layer if you need to that can intepret URL's in any way you wish. One interesting thing about the starter kit is that it allowed spaces in the Url, which actually caused some headaches for true REST fundi's.

I wasn't keen on looking at it due to WCF, but you really don't need to know that much. The solution creates everything you need, just add the code.

Diago