+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Problem with MVC widget with multiple actions

Problem with MVC widget with multiple actions

5 posts, 0 answered
  1. Neil Mercer
    Neil Mercer avatar
    10 posts
    Registered:
    24 Sep 2009
    02 Oct 2014
    Link to this post

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


  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    06 Oct 2014
    Link to this post
    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 (http://screencast.com/t/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
     
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    06 Oct 2014
    Link to this post

    @Neil

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

  4. Neil Mercer
    Neil Mercer avatar
    10 posts
    Registered:
    24 Sep 2009
    07 Oct 2014
    Link to this post

    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.

  5. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    07 Oct 2014
    Link to this post
    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
     
5 posts, 0 answered