I am trying to get thumbnail for the original image, for requested widths and heights with the help of generic handler. But I want to authorize requests to some limited set of widths and heights.
ex. 18*18, 98*94, 117*113 etc.
Anything out of these predefined sets would be treated as bad request.
So I want to save these predefined set of height and width in some kind of data structure. So that when I get request for some width and height, I can check if this belongs to predefined set. If not, I can ignore the request.. Something like:
if(PreferredWidths.Contains(requestedWidth).Index == PreferredHeights.Contains(requestedHeight).Index)
{
// Process request..
}
This was some logic, I could come up, which I want to convert in a code( Anything better is appreciated). I am not sure which data structures I should use for storing set of widths and heights. Is there any better approach, that I can use for same purpose. As any fake user can change the source of image from browser by just changing parameters of handler url (abc.ashx?Id=123&width=20&height=30). Internally, I am creating thumbnails, saving them on disk and returning urls of the same. I dont want to do this stuff, if set of requested width and height is not legal.
There is a Size struct in System.Drawing. You could just store a list of Sizes and then use: