In a previous project I used a handler to display images that were stored in a database. The url would look something like this: Thumbnail.ashx?id=1&size=150
Is this something you'd use a controller for as well? I could imagine the controller using the id to fetch the binary data, but I don't know if the controllor should call a view to actually render a bitmap to the response (including resizing) or if I should
do all that in the controller's action as well. Any tips?
Something like that I would keep in the controller, I would probably have a model service to handle all the manipulation than just call the service and write the bytes to the output stream.
Thats the best part about MVC. The controller is in charge, not the view.
You would now probably be able to give it an SEO friendly url to so it ends .jpg
random0xff
Member
102 Points
211 Posts
What about ashx handlers?
Dec 21, 2007 01:45 PM|LINK
In a previous project I used a handler to display images that were stored in a database. The url would look something like this: Thumbnail.ashx?id=1&size=150
Is this something you'd use a controller for as well? I could imagine the controller using the id to fetch the binary data, but I don't know if the controllor should call a view to actually render a bitmap to the response (including resizing) or if I should do all that in the controller's action as well. Any tips?
Thanks!
abombss
Member
575 Points
164 Posts
Re: What about ashx handlers?
Dec 21, 2007 02:01 PM|LINK
Something like that I would keep in the controller, I would probably have a model service to handle all the manipulation than just call the service and write the bytes to the output stream.
Thats the best part about MVC. The controller is in charge, not the view.
You would now probably be able to give it an SEO friendly url to so it ends .jpg
random0xff
Member
102 Points
211 Posts
Re: What about ashx handlers?
Dec 21, 2007 05:12 PM|LINK
That's clear, thanks for the tips!
mdissel
Member
47 Points
16 Posts
Re: What about ashx handlers?
Dec 21, 2007 05:31 PM|LINK
How would you do that?
Thanks
Marco
abombss
Member
575 Points
164 Posts
Re: What about ashx handlers?
Dec 21, 2007 06:28 PM|LINK
Try this and let me know if it works, haven't tested and interested myself.
new Route( Url = "gallery/thumbnails/[size]/[id].jpg", Defaults = new { Controller = "Thumbnail", Action="Show" } Validation = new { Size="75|150|300", Id="\d{1,10}" } }random0xff
Member
102 Points
211 Posts
Re: What about ashx handlers?
Dec 22, 2007 11:33 AM|LINK
That's an excellent example, thank you.