Tuesday, February 17, 2015

Resolve error “The base type <Page> is not allowed for this page. The type <Type> could not be found or it is not registered as safe” when deploying application pages with code behind using a module to SharePoint

When we deploy application pages to SharePoint, sometimes we need to deploy them to libraries or root instead of “Layouts” folder and may be with some code behind. By default SharePoint will issue above error since it violates its derived Code Access Security principles.

image 

In this case we need to explicitly add the safe control entry to web.config file. There can be following concerns.

  • What if there are multiple modules ?
  • What if we need to fully automate the deployment process without anyone manually touching config files ?

Luckily, there is a solution provided by Visual Studio itself. We can add a safe control entry to module by following the steps given below.

1. Right click your module and click Properties

image 

2. Select Safe Control Entries and Expand to add one

image

3. Add new entry and fill content accordingly

image

4. Deploy the package again

Now the page renders as expected.

image

No comments: