When getting a URL for something in an Amazon S3 bucket it can append a signature to the end to confirm that the user has permission to view the object and the URL looks like so:
https://mybucket.amazonaws.com/mykey?AWSAccessKeyId=myaccesskey& Expires=1235241261&Signature=t5vFBWXaN0DvVaWfck9n2%2fmTzOU%3d
These URLs were coming back from my S3 library as string objects and I passed them around like that. Recently I ran my code through FxCop and it recommended that I use the Uri
class to pass around URLs. I took FxCops advice and changed my URL string
properties to Uri
properties. Everything seemed to be working fine until much later I noticed that not all the objects were being fetched back successfully.
The reason for the problem was that the Uri
class ToString()
function would return a slightly different version of the URL:
https://mybucket.amazonaws.com/mykey?AWSAccessKeyId=myaccesskey& Expires=1235241261&Signature=t5vFBWXaN0DvVaWfck9n2/mTzOU=
My solution was to use the OriginalString
property of the Uri
class. But something feels wrong about this and I have two questions,
- Should I have taken FxCops advice and used the
Uri
class? - Should Amazon realize that URLs may pass through many hands and not depend on them coming back exactly the same?
For using the .Net Uri class I can be sure that my URLs are always valid but it seems to make more subtle mistakes possible.