0

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

    <%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%> 
<%@ Page Language="C#" CodeBehind="MyCustPage.cs" Inherits="CustPage.MyCustPage, CustPage, Version=1.0.0.0, 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=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, 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

2
  • Did you change namespace afterwards? Many times Namespace does not get updated. sharepoint.stackexchange.com/questions/11524/…
    – 404
    Commented Apr 22, 2015 at 10:45
  • I changed the inherits property and added code behind property to the existing wiki page
    – A Beginner
    Commented Apr 22, 2015 at 15:03

1 Answer 1

0

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

4
  • How do I register the assembly as safe? I have already added the assembly in gac.
    – A Beginner
    Commented 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
    Commented Apr 23, 2015 at 8:22
  • @MdMazzotti I am still working on it
    – A Beginner
    Commented 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
    Commented Apr 23, 2015 at 9:17

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.