I have an action method that I use to retrieve a user's picture, however some of my users might have used Facebook to log in and I don't want to return the stored picture but the one from Facebook, so I was trying something like this:
public ActionResult Picture(long id)
{
var user = UsersService.GetUser(id);
if (user.IsConnectedWithFacebook)
{
var url = "http://graph.facebook.com/" + user.GetFacebookId() + "/picture?type=square";
return Redirect(url);
}
return File(user.PictureData, user.PictureContentType);
}
and on the web page I just use:
<img src='@Url.Action("Picture", new {User.Id})' />
This works perfectly the first time I load the page, however the second time the image is not displayed. I checked calling just the action and the second time it shows a page with
"Object moved to here."
Which is why the img tag isn't loading any images.
Is there a way to prevent this from happening? I read in some other threads that people recommend to return a 301 (instead of the 302 returned by Redirect) but it returns the same page with the link (and the actual request returns a 200 instead of the 301 or 302).
Any idea on how to force it to return the redirect always?
I really don't want to add the logic to select which image to load to the page and I also don't want to request the data on the server and then return it to the page as it might be slow and become a bandwith problem.
Thanks for your help.