Logo SharePoint Thoughts   Downloads   About   Up to Bluedog Limited
A developer's point of view on understanding the "not registered on this site as safe" error message
Posted on 7/24/2005 2:38 PM by Maurice Prather
Scenario...

You’re a web part developer.  As you attempt to import your WebPart onto a page, you receive the following error:

“A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.”

What to do? 

From a developer’s standpoint there are a few things to consider.  First, it helps to understand this message is a generic message that

  1. is applied whenever an instance of WebPart cannot be created or
  2. is disallowed, either explicitly or implicitly, from rendering via the SafeControls list. 

These two conditions are very important to remember as they will help you track down the problem.

Why the generic message?

Historically it all comes down to security and the desire to not confuse users.  In the original form, a wide variety of error message were presented to the user; however, it was determined the error messages were too verbose (thus, potentially leading to questions like “and this relates to me how?”) and often times revealed too much information about the server’s configuration (information disclosure of server configuration is a big no-no).  The design team even tossed around the idea of hinging the verbose error messages to a toggle of some sorts, but the cost of wiring everything outweighed the benefits.  On top of that, the maintenance required to “translate” error conditions into user friendly context was also undesirable due to complexity and the unbounded number of possible error messages.  Therefore, the decision was made to fit web parts into two buckets – those that can be rendered and those which cannot.  For those which cannot, they are generically stamped as being unsafe.

What is the solution?

As mentioned earlier, there are two failure areas – deserialization errors and administrative actions.

  1. Obviously, the first thing to check is whether or not a SafeControl entry exists.
    1. Did you specify the correct assembly name?
    2. How about version, culture, and public key token? 
    3. Did you specify the correct namespace?
    4. Did you specify the correct type name?
    5. Is it marked as Safe=”true”?

For the assembly name, I always recommend using the assembly full name instead of simply using the assembly name.  Why?  It’s better resolution and provides you with guaranteed operation with FP2003 (it has an issue where non-strongly named assemblies need to be referenced by the full name).
 

  1. Check if the DWP matches the SafeControl entry. 

    You would be surprised how many times folks get this simple requirement wrong.  Open up your dwp and verify the entries in the web.config matches your dwps.
  2. Ensure the assembly is properly installed.

    The SharePoint Configuration Analyzer can help you isolate problems associated with hints 1 and 3.

    If you want a handy tool which will generate the correct SafeControl and DWPs, check out InstallAssemblies.exe which is available in the Web Part Toolkit, which shipped with the Resource Kit.
  1. The web part is unable to initialize because an unhandled exception occurs in either the constructor or a property setter.

    This is the number one gotcha for most developers.  A classic example of how this manifests itself can be seen when code access security permissions are tightened or perhaps moving usage from an SPS site over to a WSS site (or vice versa).
  2. A custom namespace for the web part properties has not been provided.  The developer must specify a custom namespace at either the class level or the property level.
  3. The developer has not specified either a DefaultValueAttribute or implemented a ShouldSerializeXXX method for a property.
  4. The developer has forgotten to remove wildcard versioning for the assembly.  This results in a mismatch between the SafeControl/dwp and the assembly itself each time the assembly is compiled.

    The last three are the most common newbie problems.  Once you’ve written a couple of parts, this practically becomes a non-issue.
  5. The xml serializer cannot create temp files and/or disk space is limited. See KB 826786.
  6. Is your web part referencing a library and is running with less than Full trust?  If so, your web part may not be allowed to load unless the APTCA bit is enabled on the library assembly.

For more information on code access security, please read the following documents and posts:

·         Microsoft Windows SharePoint Services and Code Access Security

·         Code Access Security Q&A (previous post on this site)

Security note: Developers new to code access security should take the time to understand the requirements of running as partially trusted code, but more importantly what it may mean to them if they build library assemblies with AllowPartiallyTrustedCallers attribute set.

Is more information available when this problem occurs?

Yes and no.  In some instances, the very first time a deserialization error occurs (4-8), the error message presented to the user may actually contain a more descriptive context (i.e. “no default value has been specified”).  However, all subsequent occurrences will result in the "cannot deserialize the Web Part" error message.

“Web Part Error: One of the properties of the Web Part has an incorrect format. Windows SharePoint Services cannot deserialize the Web Part. Check the format of the properties and try again.”

If you don’t see the deserialization error, you will see the “not registered on this site as safe” message.  The reason “proper” error messages are only seen on first render is simply because the errors are not cached and, therefore, subsequent hits fall through to the generic error message.

In short, no information is cached or recorded.  It’s basically wysiwyg.

The exception to the rule – code access security exceptions are logged

In the event a code access security exception is encountered, the exception is recorded in the server’s application event log.  This applies to the SecurityException and PolicyException exceptions only. 

What causes my page to blow up and redirect me to the web part maintenance page?

If you import a web part onto a page and you are immediately redirected to the web part maintenance page (aka. the contents page), this is an indication that an exception was thrown and not properly handled by the web part.  If this is the case, your web part has met the requirements for a SafeControl and is actually executing.  It’s now your job as the developer to determine why the exception was thrown and how to best handle it.... :)

Many folks argue that there should be more than two buckets... I agree, but knowing what causes the error certainly helps narrow down the scope.

-Maurice

re: A developer's point of view on understanding the "not registered on this site as safe" error message
Regarding the "Manage Web Part Page", I've been having trouble with some custom web parts that work fine on the page but show up as having "Error" in the title and/or "ErrorWebPart" in the Type field.
 
I've found that installing the web part into the GAC resolves this issue, however, I do not understand why my other web parts don't have this problem.
 
Just to re-iterate, the web parts are functioning fine but show errors in the "Manage Web Part Page" page. Could it be related to some deployment error?
 
Kwan Lim @ 7/26/2005 12:56 PM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
It's a configuration issue... the following post should help.
Note the link for the KB article at the bottom.
 
 
Bluedog @ 7/26/2005 6:42 PM
Thanks for the info. Placing the web part in the GAC does get rid of the error messages.
However, what I still don't understand is why my other custom web parts that are on the same page and installed in the BIN folder don't have the error messages on the Manage Web Parts page. And I'm not using host headers or static inbound IPs.
Kwan Lim @ 7/27/2005 7:27 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Kwan,
 
If you are running a supported configuration and other bin-installed web parts are working properly, there is a chance you are running into a code access security issue.  This would begin to explain why it works ok in the GAC, but reports an error in the BIN.  My guess is that your code is making some kind of assumption of the state of the page such that when the maintenance page opens, a cas-protected method is called and the part throws an exception.  The difference between rendering on a page and simple instantiation is where you should focus your attention.
Maurice Prather @ 7/28/2005 12:35 PM
Thanks for your help Maurice.
I've tried to narrow the possible errors down but still can't determine the problem. I've even tried setting the trust level to full but I still get the error.
A peculiar thing is that when I first deploy the WPP it works fine but sometime later the error crops up. Also, the Web Part Type field doesn't say ErrorWebPart but changes from last part of the full type name to full period seperated type name.
I'll try to do more investigating to see what I may be doing differently in this web part. But it'd sure be nice to know how that "Manage Web Parts" page works.
Kwan Lim @ 8/2/2005 8:17 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
I've discovered the cause of the "Error" messages in "Web Part Title" has to do with assembly binding problems. The runtime tries to load the web part assemblies from C:\program files\common files\microsoft shared\web server extensions\60\layouts\bin instead of c:\inetpub\webapp\bin.
 
I've verified that by placing the assembly in layouts\bin the errors are gone, however, this is more of a sympton than the cause. I wonder how it got to such a state.
Kwan Lim @ 8/8/2005 8:38 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Don't install your web parts in any bin directory other than the main virtual directory.  Between the GAC and bin, those are the only two place where SharePoint supports the addition of web part assemblies. 
 
Yes, the CLR will look in the "bin" folder of each virtual directory but that does not mean you need to place a web part assembly in each one.
 
To help you further determine the cause of failure, have you considered the following?
  • Does your web part assembly rely on other library assemblies?
  • Does this error occur based on timing?  In other words, after an IISRESET, will you see the error after navigating to the page first, then the contents page?  Or perhaps you only see the error when you navigate to the contents page first after a reset?

To answer your question about how the maintenance page works: the page simply instantiates your web parts.  Nothing else.  If the part can be instantiated, you will see the proper information.  Otherwise, you will see errors.

Again, look at your code.  If some parts are OK but other are not, it's a good sign that you are doing something vastly different between types.

Maurice Prather @ 8/8/2005 10:46 AM
Thanks again Maurice.
I double checked the references between assemblies and that's what was causing the errors. I can't believe how much time I spent on this...
Kwan Lim @ 8/9/2005 11:45 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Can you please elaborate on what kind of checks you made on your assemblies. I am getting the same 'Error' message in the webpart title. However my webpart renders successfully and functions as designed. I have deployed my webpart in the bin folder. It refers to another library which is also in the bin folder.
 
Thanks
Anonymous User @ 10/5/2005 8:50 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
This sounds like KB 830342, which has been fixed in SP2.  Read the following post for more info...
-Maurice
Maurice Prather @ 10/20/2005 11:02 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Make sure that
the Windows\Temp (%temp%) directory has permissions for the STS_WPG process.
me @ 3/29/2006 2:01 AM
“A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.”
actually i am developing a new custom web part.but at time importing the web part in out site i am getting the error " “A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.”
 
plz give me some idea why the error r coming.
sanjeev @ 5/4/2006 5:09 AM
sharepoint
how to upload a .dwp file in a remote machine created in a local machine
 
Anonymous User @ 6/21/2006 11:32 PM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Hi. I am developing a web part that relies on some external assemblies. I have packaged the web part assembly and the other dlls into a cab and it all deploys ok; ie all the assemblies are in the GAC and all the assemblies are in the web.config as safe. All assemblies are built with strong names and have public keys. But I still get this message.
 
If I comment out the relevent bits and remove the dependancies and rebuild and deploy with only the web part dll it all works ok.
 
So I guess I am messing up in the way the additional dependancies are being used. Can anyone offer any advice or thoughts on how I can track down the problem?
Paul Bedford @ 8/29/2006 7:34 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Well, i have the same problem too.
 
But i develop using the web part using visual studio 2005 and imported into sharepoint 2003.
 
Is it OK? I think my problem happen because i develop in framework 2.0 and i import into framework 1.1
 
Do you have a solution for me? I still want using vs 2005.
 
Thanx,
 
 
Nyo
Ricky Nyo @ 9/11/2006 1:03 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
By default SP site use .Net FW 1.0...
If you make WebPart with FW 2.0 u got topic message when place WebPart on page.
Change site setting ASP.Net to use FW 2.0 then read
It solve my case.
mclabman @ 11/13/2006 9:37 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Hi, I have registered web part assembly in GAC and bin directory and both safe controls section in web. config and .dwp file are same. Still i am getting error message  "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe" while adding web part in sharepoint site.
 
Please do the needful.
Prakash @ 12/7/2006 4:37 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
Here is my story how I overcame this error message. After successfully building my webpart I placed it in the GAC. I registered it as safe in Web.config and specified full assembly definition in .dwp files (with version, public key token, etc.). However hard I tried, ANY webpart from this assembly caused the above mentioned error to appear. Finally, I started to think that the problem is with my code. I excluded all the code files except one empty webpart which surprisingly worked fine. I found that the problem is that my assembly fails to load due to the reference to an assembly that was not in GAC. There was some code using that assembly, so when I excluded it from the project and removed the reference, all web parts started to work fine. Prakash, try this, the problem may be with your code.
PavelBure @ 12/28/2006 8:59 AM
Data Viewer Web part in WSS 3.0 server
i used Data Viewer web part, and supply for it a RSS Feed, it works properly, but when we apply it in the same server version of WSS 3.0 but in another network, it gives me "not registered"
Anonymous User @ 7/17/2007 12:55 AM
re: A developer's point of view on understanding the "not registered on this site as safe" error message
doube check your WEB.CONFIG safecontrol Assembly line.
 
      <SafeControl Assembly="somewepbartname, Version=1.0.0.0,Culture=neutral, PublicKeyToken=34356a5bbc942f16" Namespace="something.somethingelse.UI" TypeName="somewepbartname" Safe="True" />
We had a typo .. TypeName=" somewepbartname " .  note the extra spaces.  yeah, that cost us some time. D'oh.
Anonymous User @ 12/6/2009 9:43 AM
RSS feed
Microsoft Certified Master
MVP Logo
Follow me on Twitter!
Keyword Search
 
View by category
 

Disclaimer:
The contents of this site represent thoughts and opinions of the authors , not those of anyone else - such as past, present and future employers.  This a forum of the exchange of ideas centered on SharePoint technologies.  It is not a support channel.  :)

Copyright © 2004-2010 Maurice Prather, Inc. All rights reserved.