+1  A: 

EDIT: Original suggestion which apparently doesn't work

I'm sure the reason is that it thinks it's a query parameter called Key. Could you make it a parameter, with that part being the value, e.g.

www.example.com/Find?Route=Key=

I expect that would work (as the parser would be looking for an & to start the next parameter) but it's possible it'll confuse things still.

Suggestion which I believe will work

Alternatively, replace "=" in the base64 encoded value with something else on the way out, and re-replace it on the way back in, if you see what I mean. Basically use a different base64 decodabet.

Alternative suggestion which should work

Before adding base64 to the URL:

private static readonly char[] Base64Padding = new char[] { '=' };
...
base64 = base64.TrimEnd(Base64Padding);

Then before calling Convert.FromBase64String() (which is what I assume you're doing) on the inbound request:

// Round up to a multiple of 4 characters.
int paddedLength = (4 - (base64.Length % 4)) % 4; 
base64 = base64.PadRight(paddedLength, '=');
Jon Skeet
Alex
Could you add an explanation on what your 'alternative suggestion' code does? Thank you :)
Alex
A: 

UrlEncode the encrypted (it is encrypted, right?) parameter.

If it is an encrypted string, beware that spaces and the + character will also get in your way.


Ok, so IIS 7 won't allow some special characters as part of your path. However, it would allow them if they were part of the querystring.

It is apparently, possible, to change this with a reg hack, but I wouldn't recommend that.

What I would suggest, then, is to use an alternate token, as suggested by Mr Skeet, or simply do not use it in your path, use it as querystring, where you CAN url encode it.

If it is an encrypted string, you haven't verified that it is or is not, you may in some cases get other 'illegal' characters. Querystring really would be the way to go.


Except your sample shows it as querystring... So what gives? Where did you find an IIS that won't allow standard uri encoding as part of the querystring??


Ok then. Thanks for the update.

RequestFiltering? I see. Still that mentions double-encoded values that it blocks. Someone created a URL Sequence to deny any request with the '%' characters? At that point you might want to not use the encrypted string at all, but generate a GUID or something else that is guaranteed to not contain special characters, yet is not trivial to guess.

Chad Ruppert
I've already made the Base64 string "url friendly" by replacing "+" with "-" and "/" with "_". Base64 doesn't encode into spaces.
Alex
a url encode would turn teh = to %3D
Venr
Exactly. Url encode. dont do it yourself. You'll never catch it all on your first few tries.
Chad Ruppert
Write a helper to do it for you if you don't want to pepper your code everywhere with urlencodes. Trust me, I've gone through the passing encrypted strings with the url a bajillion times. URLEncode. It will save your bacon.
Chad Ruppert
Here's the problem though. The IIS I'm writing against does not allow %. That's why I didn't even use UrlEncode to begin with.
Alex
I see. its not that it won't allow %. It won't allow percents in the *path*. querystrings it would allow
Chad Ruppert
Or do you have some really strange IIS that doesn't follow the RFCs for uri formatting? Not being sarcastic, trying to understand your flavor of IIS?
Chad Ruppert
Hey, this is restricted in the IIS urlscan equivalent (forgot what its called, routingparameters or similar). It's a given for me.
Alex
+1  A: 

IF you're passing data in the URL you should probably URL Encode it which would take care of the trailing =.

http://www.albionresearch.com/misc/urlencode.php

Venr