Problem with MVC widget with multiple actions
Hi,
I have a MVC widget that pulls information from our Active Directory to display for the user. One of the data items is an image stored within the directory. In order to be able to present the image, I've added an Action to the Controller for the View to be able to request the image. It also includes returning a default image should the directory not contain an image.
However, when viewing the widget on a Sitefinity page, the images never show. I've used Fiddler to confirm that the requests are being made from the View, and I can debug the code to see it is hitting the Action. The odd thing is that Fiddler is showing the return from the Action being the whole View, not the image I wanted.
Any ideas? The code for the Action on the Controller is below (I'm sure this must be where the problem is)
public
ActionResult GetImage(
string
firstName,
string
lastName)
List<StaffMember> lstStaff =
new
List<StaffMember>();
string
DomainPath =
"LDAP://DC=douglas,DC=local"
;
DirectoryEntry searchRoot =
new
DirectoryEntry(DomainPath);
DirectorySearcher search =
new
DirectorySearcher(searchRoot);
search.Filter =
"(&(objectClass=user)(objectCategory=person)(giveName="
+firstName+
")(sn="
+lastName+
"))"
;
search.PropertiesToLoad.Add(
"thumbnailPhoto"
);
SearchResult result;
SearchResultCollection resultCol = search.FindAll();
if
(resultCol !=
null
)
for
(
int
counter = 0; counter < resultCol.Count; counter++)
result = resultCol[counter];
if
(result.Properties.Contains(
"thumbnailPhoto"
))
byte
[] data = result.Properties[
"thumbnailPhoto"
][0]
as
byte
[];
if
(data !=
null
)
using
(MemoryStream s =
new
MemoryStream(data))
return
new
FileStreamResult(s,
"image/jpeg"
);
string
filename = Server.MapPath(
"/images/UnknownPerson.jpg"
);
return
new
FilePathResult(filename,
"image/jpeg"
);
Hello Neil,
I am not able to reproduce the issue on my end. Both FilePathResult and FileStreamResult work fine on Sitefinity 7.2. Could you please specify the Sitefinity version you are using? Here is a video (screencast.com/.../bsm2AWj4b) showing the actions functionality in a simple widget.
Regards,
Nikola Zagorchev
Telerik
@Neil
Is your default sitefinity images library setup to serve images from /images? ...maybe like a path conflict?
Hi Nikola,
I was running the project under 7.1. As you had it working on 7.2, I've just upgraded the project to 7.2, and now it works! So, I guess it must have been a bug in 7.1?
Thanks,
Neil.
Hello Neil,
The issue with FileResult and I/O actions was fixed in internal build 7.1.5213. You can review the bug that is fixed here.
Regards,
Nikola Zagorchev
Telerik