Problem with MVC widget with multiple actions

Posted by Community Admin on 04-Aug-2018 04:05

Problem with MVC widget with multiple actions

All Replies

Posted by Community Admin on 02-Oct-2014 00:00

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");


Posted by Community Admin on 06-Oct-2014 00:00
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
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
Posted by Community Admin on 06-Oct-2014 00:00

@Neil

 Is your default sitefinity images library setup to serve images from /images?  ...maybe like a path conflict?

Posted by Community Admin on 07-Oct-2014 00:00

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.

Posted by Community Admin on 07-Oct-2014 00:00
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
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
This thread is closed