问题
I'm just getting started with ImageResizer and I'm stuck on what seem like totally basic questions:
- I have an uploader that I use to put images into a directory that's not directly accessible over HTTP. (If I just put a image at, say,
/images/myimage.jpg
, then anyone could access it by just asking for it, whereas I want to limit access via thumbnails, watermarks, etc.). So I want to put it at/offlimits/myimage.jpg
, but be able to serve it up at/public/images/myimage.jpg
. - I don't really want to dump all the images in the same
offlimits
folder, because putting lots of files in one folder makes Windows unhappy. But I don't want to expose the details of that subdirectory structure either, so where do I put the mapping between the public facing url and the actual image location? - Most generally, I don't necessarily want an image extension at all, so I'd like to say
/public/image_id?width=100...
and have this map to/offlimits/sub1/sub2/sub3/image_id.jpg
.
Can anyone advise about how to set this up?
回答1:
Three part questions are generally frowned upon here at SO, but I'll bite anyhow :)
- If you're allowing access to images based on authentication, then you need to use ASP.NET's URL Authorization feature. ImageResizer supports URL Authorization rules. If you just don't want the source files available, and want to force them resized or watermarked, read the docs on how to implement arbitrary rules like this.
- You can rewrite image paths to your heart's content with
Config.Current.Rewrite
, which works just like the PostRewrite event mentioned earlier. Just remember you'll have to keep it all straight in your head later. - Image extensions are good things. Don't fight them. They let the server figure out the right mime-type to send and help errant browsers recover from related bugs. They prevent issues on several platforms and make the Save As dialog work. They significantly improve server efficiency as well, since handling logic doesn't have wait as long. This is particularly relevant because of the design of the IIS/ASP.NET modules system.
来源:https://stackoverflow.com/questions/11299837/how-can-i-set-up-custom-imageresizer-urls