I am creating a code behind file for the site page of sharepoint. The following page directive was used

    <%@ Assembly Name="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%> 
<%@ Page Language="C#" CodeBehind="MyCustPage.cs" Inherits="CustPage.MyCustPage, CustPage, Version=, Culture=neutral, PublicKeyToken=44ba9bb23d3f44ca" MasterPageFile="~masterurl/default.master" meta:progid="SharePoint.WebPartPage.Document"       %>
<%@ Import Namespace="Microsoft.SharePoint.WebPartPages" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

My .cs file is as follows

   using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace CustPage
    public class MyCustPage:Page
        protected void Page_Load(object sender, EventArgs e)
            Response.Write("<script>alert('it worked')</script>");

I am getting this error :

The base type 'CustPage.MyCustPage' is not allowed for this page. The type is not registered as safe.

I have only done two things : first create an aspx file and then a separate class library. Any help would be appreciated


1 Answer 1


You have to register your assembly as safe to the SharePoint. If can set this property manually or do it with Visual Studio. Here is some references:

  1. "The type is not registered as safe" when trying to add a web part installed by a WSP
  2. http://www.ableblue.com/blog/archive/2010/08/20/adding-safe-controls-entries-in-visual-studio-2010/

  3. http://blogit.create.pt/andrevala/2010/08/22/adding-an-assembly-to-safe-controls-in-sharepoint-tools-for-visual-studio-2010/

  4. https://msdn.microsoft.com/en-us/library/ee805045.aspx

Keep in mind that you have to sign your assembly with SNK key to add it to Global Assembly Cache

  • How do I register the assembly as safe? I have already added the assembly in gac.
    – A Beginner
    Apr 22, 2015 at 15:02
  • @ABeginner any update on your issue? ECM4D gave you some good indications. As a good habit, you should report back your findings and, most of all, mark the answer as helpful and/or accepted
    – MdMazzotti
    Apr 23, 2015 at 8:22
  • @MdMazzotti I am still working on it
    – A Beginner
    Apr 23, 2015 at 8:27
  • In your project add new empty element (or use existing one if it is), open properties of this element and you can see Safe Control property where you can specify you assembly as safe control. Please follow instructions on ableblue.com/blog/archive/2010/08/20/… . Is is exactly what you need.
    – ECM4D
    Apr 23, 2015 at 9:17

Your Answer

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

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