0
votes

I am using iFrame as the field type in one of my Sitecore Template. In the source field of the iFrame field, I mentioned the route to my Controller action.

FieldType: IFrame
Source: /mvc/modules/products/getList

And in the routeconfig.cs file I configured the route as

        routes.MapRoute(
            "SitecoreModulesDefault",
            "/mvc/modules/{controller}/{action}",
            new { controller = "products", action = "getList" }
        );

Then i create a content item of the above template type. When I check the the iFrame field, I see that the controller is not being called and I am seeing the error as "The requested document was not found" with the below Additional Information:

Requested URL: /mvc/modules/products/getList
User Name: sitecore\admin
Site Name: website

Some how the route is not redirecting to the controller action. Is there anything else to configure or Am I doing something wrong somewhere? Thanks in advance!

Note: I am using Sitecore 8.1 with MVC. Also, I cannot use a .aspx file here instead of a controller.

1

1 Answers

0
votes

It looks like Sitecore is picking up the Url and processing it, but because you don't have the Sitecore items setup for that Url it will give you a 404 error.

You have 2 options:

  1. Add your url to the IgnoreUrlPrefixes setting:

<setting name="IgnoreUrlPrefixes" value="/mvc/modules/|... all original values ..."/>

  1. Create an item that matches your required Url for the IFrame and set the presentation on it to use your controller action as a Controller Rendering

There are pros and cons to both options. For option 1, a downside is that you will not have a Sitecore context to work with, this may or may not be a problem depending on your code. On the plus side, you can't "break" the IFrame content by messing something up in the content editor.

Option 2 has the advantage that it works like other Sitecore pages, you can make use of Sitecore's output cache to help performance, and changes to presentation do not have to be code based. On the downside, you would be reliant on an item structure so you would have to make sure the security is set correctly to prevent unwanted changes to it.

Overall, I think for rendered Html output, option 2 is generally the way I like to do it as it gives you a bit more flexibility. But both options work well.

If you go with option 1, this post gives an alternative way of patching the Ignore list: http://www.awareweb.com/awareblog/12-14-15-patchableignorelist