4

I am using sharepoint 2010 and have a custom masterpage. In this masterpage I am using a servercontrol. This servercontrol is not an ascx file, but a c# class which inherit from the HTMLAnchor OOTB .NET control. In this class I override the OnPreRender method. In my masterpage I register this class as follow:

<%@ Register TagPrefix="RNWC" Namespace="MyCompany.Portaal.WebControls" Assembly="MyCompany.Portaal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0706e2b063d8c945" %>

In my html I am using the following servercontrol:

<RNWC:PortalConnectionAnchor runat="server">                                    <SharePoint:SiteLogoImage name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/images/siteIcon.png" runat="server"/>
                                        </RNWC:PortalConnectionAnchor>

The problem is now, when I try to edit this masterpage in sharepoint designer and save the change, I got this warning: Saving your changes will customize this page so that it is no longer based on the site definition. Do you want to continue?

When I press on yes and save my changes (for example only a space in the html) and refresh my site I got the following error:

Type is not registered as safe

When I add this in my web.config file of the web application it is resolved:

<SafeControl Assembly="MyCompany.Portaal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0706e2b063d8c945" Namespace="MyCompany.Portaal.WebControls" TypeName="*" Safe="True" SafeAgainstScript="False" />

I don't want to add this manually in the config file. What is the best practice to fix this problem?

This is my servercontrol class:

namespace MyCompany.Portaal.WebControls
{
    /// <summary>
    /// Defines the PortalConnectionAnchor class.
    /// </summary>
    public class PortalConnectionAnchor : HtmlAnchor
    {
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event and registers client script for generating a postback.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            var rootUrl = ConfigListHelper.GetConfigValue("RootUrl");

            if (!string.IsNullOrEmpty(rootUrl))
            {
                HRef = rootUrl;
            }
            else
            {
                HRef = GetPortalConnection();
            }

            base.OnPreRender(e);
        }

1 Answer 1

1

If you edit your master page from SharePoint Designer then it goes into un-ghosted state and hence SharePoint will use type-safe parsers on all the un-ghosted content.

Make sure that you upgrade/edit your master pages using the Feature activation way. You can check the the following answer with source code is already provided: How to update custom master page and page layout, which is already deployed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.