Sharepoint : Access denied when editing a page (because of page layout) or list item

admin

Administrator
Staff member
I'm logged in as the System Account, so it's probably not a "real access denied"!
What I've done :
- A custom master page
- A custom page layout from a custom content type (with custom fields)

If I add a custom field (aka "content field" in the tools in SPD) in my page layout, I get an access denied when I try to edit a page that comes from that page layout.

So, for example, if I add in my page layout this line in a "asp:content" tag :


I get an access denied. If I remove it, everyting is fine. (the field "test" is a field that comes from the content type).

Any idea?

<strong>UPDATE</strong>

Well, I tried in a blank site and it worked fine, so there must be something wrong with my web application :(

<strong>UPDATE #2</strong>

Looks like this line in the master page gives me the access denied :

Code:
&lt;SharePoint:DelegateControl runat="server" ControlId="PublishingConsole" Visible="false"
    PrefixHtml="&amp;lt;tr&amp;gt;&amp;lt;td colspan=&amp;quot;0&amp;quot; id=&amp;quot;mpdmconsole&amp;quot; class=&amp;quot;s2i-consolemptablerow&amp;quot;&amp;gt;"
    SuffixHtml="&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;"&gt;&lt;/SharePoint:DelegateControl&gt;

<strong>UPDATE #3</strong>

I Found <a href="http://odole.wordpress.com/2009/01/...s-of-any-document-in-a-moss-document-library/" rel="nofollow noreferrer">http://odole.wordpress.com/2009/01/...s-of-any-document-in-a-moss-document-library/</a>

Looks like a similar issue. But our Sharepoint versions are with the latest updates. I'll try to use the code that's supposed to fix the lists and post another update.

** UPDATE #4**

OK... I tried the code that I found on the page above (see link) and it seems to fix the thing. I haven't tested the solution at 100% but so far, so good. Here's the code I made for a feature receiver (I used the code posted from the link above) :

Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

using System.Xml;

namespace MyWebsite.FixAccessDenied
{
    class FixAccessDenied : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            FixWebField(SPContext.Current.Web);
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            //throw new Exception("The method or operation is not implemented.");
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            //throw new Exception("The method or operation is not implemented.");
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            //throw new Exception("The method or operation is not implemented.");
        }

        static void FixWebField(SPWeb currentWeb)
        {

            string RenderXMLPattenAttribute = "RenderXMLUsingPattern";

            SPSite site = new SPSite(currentWeb.Url);
            SPWeb web = site.OpenWeb();

            web.AllowUnsafeUpdates = true;
            web.Update();

            SPField f = web.Fields.GetFieldByInternalName("PermMask");
            string s = f.SchemaXml;
            Console.WriteLine("schemaXml before: " + s);
            XmlDocument xd = new XmlDocument();
            xd.LoadXml(s);
            XmlElement xe = xd.DocumentElement;
            if (xe.Attributes[RenderXMLPattenAttribute] == null)
            {
                XmlAttribute attr = xd.CreateAttribute(RenderXMLPattenAttribute);
                attr.Value = "TRUE";
                xe.Attributes.Append(attr);
            }

            string strXml = xe.OuterXml;
            Console.WriteLine("schemaXml after: " + strXml);
            f.SchemaXml = strXml;

            foreach (SPWeb sites in site.AllWebs)
            {
                FixField(sites.Url);
            }

        }

        static void FixField(string weburl)
        {
            string RenderXMLPattenAttribute = "RenderXMLUsingPattern";

            SPSite site = new SPSite(weburl);
            SPWeb web = site.OpenWeb();
            web.AllowUnsafeUpdates = true;
            web.Update();

            System.Collections.Generic.IList&lt;Guid&gt; guidArrayList = new System.Collections.Generic.List&lt;Guid&gt;();

            foreach (SPList list in web.Lists)
            {
                guidArrayList.Add(list.ID);
            }

            foreach (Guid guid in guidArrayList)
            {
                SPList list = web.Lists[guid];
                SPField f = list.Fields.GetFieldByInternalName("PermMask");
                string s = f.SchemaXml;
                Console.WriteLine("schemaXml before: " + s);
                XmlDocument xd = new XmlDocument();
                xd.LoadXml(s);
                XmlElement xe = xd.DocumentElement;
                if (xe.Attributes[RenderXMLPattenAttribute] == null)
                {
                    XmlAttribute attr = xd.CreateAttribute(RenderXMLPattenAttribute);
                    attr.Value = "TRUE";
                    xe.Attributes.Append(attr);
                }
                string strXml = xe.OuterXml;
                Console.WriteLine("schemaXml after: " + strXml);
                f.SchemaXml = strXml;
            }

        }

    }
}

Just put that code as a Feature Receiver, and activate it at the root site, it should loop trough all the subsites and fix the lists.

<strong>SUMMARY</strong>

You get an <strong>ACCESS DENIED</strong> when editing a <strong>PAGE</strong> or an <strong>ITEM</strong>

You still get the error even if you're logged in as the Super Admin of the f****in world (sorry, I spent 3 days on that bug)

For me, it happened after an import from another site definition (a cmp file)

Actually, it's supposed to be a known bug and it's supposed to be fixed since February 2009, but it looks like it's not.

The code I posted above should fix the thing.