I wanted to share one of the issue which we have resolved
while working on one of the project.

 

We were having one anonymous site having visual web parts
and custom web parts.

And the Issue was that whenever we were deploying the site,
and were trying to open the site for the first time via anonymous user, all the
custom web parts and visual web parts were giving the error

 

“A Web Part or Web Form Control on this Page cannot be
displayed or imported. You don't have Add and Customize Pages permissions
required to perform this action”

 

So, as a work around, we were doing login by system account
and then were accessing all the sites. After that we were able to access those
web parts via anonymous user

 

Issue: If you want to access the Custom web parts,
via anonymous user, there should be an entry in the web config that this is a
safe control and SafeAgainstScript should be true.

In our case, the entry was there but the type name was “*”
and SafeAgainstScript was set to false.

 

Resolution: Whenever we create the custom web part or
visual web part, by default the SafeAgaintScript attribute is set to false under
SharePointProjectItem.spdata. I changed the SafeAgainstScript to True which
will automatically come under the web config during deployment. In our case,
the entry was like this:

 

<SafeControl Assembly="" Namespace="" TypeName="*WebPart" Safe="True" SafeAgainstScript="True" />

     
<SafeControl Assembly="" Namespace="" TypeName="*WebPart" Safe="True" SafeAgainstScript="True" />

 

which resolved the issue.