1

Resolved

SharePoint 2013 App - Item has already been added. Key in dictionary: AllowFraming

description

I downloaded and installed the Ventigrate.Shared.PermissiveXFrameHeader.wsp into SharePoint 2013. Now that it has been enabled for the site I get this error when I try to open my App from the site:

Application error when access /_layouts/15/appredirect.aspx, Error=Item has already been added. Key in dictionary: 'AllowFraming' Key being added: 'AllowFraming' at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at Microsoft.SharePoint.ApplicationPages.AppRedirectPage.HandleRequest() at Microsoft.SharePoint.ApplicationPages.AppRedirectPage.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

comments

vandest wrote Mar 16, 2015 at 12:15 PM

Hi, this has been fixed in today's release.

joshuadeaver wrote Sep 29, 2015 at 2:27 PM

This issue still is open - the http handler breaks the appredirect.aspx page when opening an app (in my case an Access App). I am running Sharepoint 2013 Enterprise with all of the latest updates.

CodeMasterTom wrote Oct 15, 2015 at 4:32 PM

Can confirm, this issue is still open, I'm also running into the same error when trying to load the AppRedirect.aspx page (in my case I was testing a brand-new "Hello World" SharePoint-hosted app).

Looks like it's because inside Microsoft.SharePoint.ApplicationPages.AppRedirectPage.HandleRequest() method there is the following line which gets called without checking whether "AllowFraming" is already in this.Context.Items:
private void HandleRequest()
{
    // ... snip ...
    this.Context.Items.Add(SPRequestModule.AllowFramingFlag, "1");
    // ... snip ...
}
I changed PermissiveXFrameHeaderModule.cs by removing context_BeginRequest method and put that code into context_EndRequest. This seems to fix it for me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Ventigrate.Shared.PermissiveXFrameHeader.Modules
{
    public class PermissiveXFrameHeaderModule : IHttpModule
    {
        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.EndRequest += context_EndRequest;
        }

        protected void context_EndRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;

            // General requests
            if (!context.Items.Contains("AllowFraming"))
                context.Items.Add("AllowFraming", String.Empty);

            // IPFS requests
            if (!context.Items.Contains("FrameOptionsHeaderSet"))
                context.Items.Add("FrameOptionsHeaderSet", String.Empty);

            // XLViewer
            context.Response.Headers.Remove("X-FRAME-OPTIONS");
        }
    }
}

baconbum wrote Oct 15, 2015 at 5:44 PM

I agree with FunkMasterTom. Not only did his proposed solution fix my problem, it also gave me the strength and courage to achieve the following:
  • Ask out a woman
  • Grow a beard
  • Wrestle a grizzly bear
  • Chop down a tree with my bare hands
  • Filibuster an unjust bill for 72 hours straight
  • Create a perpetual motion machine using just a few pieces of scrap metal and a while loop
  • Take down the Yakuza
Thank you FunkMasterTom.

vandest wrote Oct 16, 2015 at 7:17 AM

Thanks for the update. I'll review it asap and modify when validated.

vandest wrote Oct 21, 2015 at 2:40 PM

Hi,

Your proposed change has been incorporated into the code and download. Thanks for your contribution!

Swanl wrote Jul 6, 2016 at 4:13 PM

Hi

I have an earlier version installed and working. I want to install this update version to fix this framing error.

Could you advice what the steps I need to do to install this update version? uninstall old one first or overwrite with new one..

Thanks

Swanl

vandest wrote Jul 6, 2016 at 6:19 PM

You can run Update-SPSolution to just do the upgrade. If you prefer Retract and Deploy be sure to disable the Web Application Feature on all (active) Web Apps first before retracting.


HTH

Swanl wrote Jul 6, 2016 at 8:13 PM

Hi

I did an Update-SPSolution and it ran successfully and worked like a champ.
The issue is now resolved. I was able to add and open Apps from App Store.

Thanks so much for you advice

Swanl

Swanl wrote Jul 21, 2016 at 9:20 PM

Hi

I like to find check to see if all my SP farms run on the same version of this solution.
Is there a way to check the version of this solution installed?

Thanks

Swanl

vandest wrote Jul 22, 2016 at 6:53 AM

Hi,

Sorry but there's no versioning built into the package. If you're any handy with ILSpy or Reflector you could open up the deployed assembly (in GAC) and see if the code matches the latest modifications? Cumbersome work but avoids having to update the solution (with downtime).

Cheers