How to identify an unsafe web part / control

3.8k views Asked by At

I get an error when trying to edit a page in a SharePoint site. Using WinDbg I see that actual error is:

Microsoft.SharePoint.ApplicationRuntime.SafeControls+UnsafeControlException

This looks to me like I have a control on the page which is not included in the <SafeControls> section of web.config. I've had a look at the aspx file for the page, but I can't see any controls on there which don't have a reference in web.config.

Digging a little deeper (and using Sosex.dll) I got the following data from the callstack which lead up to the error:

0:013> !mframe 03
0:013> !mdv
Frame 0x3: (Microsoft.SharePoint.ApplicationRuntime.SafeControls.GetTypeFromGuid(System.Guid)):
[A0]:this:0xc00c03e8 (Microsoft.SharePoint.ApplicationRuntime.SafeControls)
[A1]:guid:{ef2d8253-a451-56da-be1d-5f32d5227173} VALTYPE (MT=0000064278430ea8, ADDR=000000000308caa0) (System.Guid)
[L0]:null (System.Type)
[L1]:0x633c50 (System.String) STRVAL=The type could not be found or it is not registered as safe.
[L2]:null (System.Type)

So it looks like I've found the GUID of the control ([A1]) which is causing the problem. Howver, I don't know of a way to find which control this GUID is referencing. There must be a table somewhere in SQL Server whih stores this information? I've already tried dbo.WebParts, selecting against tp_ID with the GUID, but it found nothing. I guess I'm missing something?

3

There are 3 answers

0
Janis Veinbergs On

To manipulate Web parts programmatically, you can use SPLimitedWebPartManager

See this article to find the idea of how you would remove or locate webpart from page.

With debugger it should be fairly easy to list all those webparts and just see coressponding DisplayTitle for your particular ID.

0
Ryan On

Whoa there! Back slowly away from the SQL Server ;)

First thing to look at is the difference between a closed web part and a deleted web part.

Closed is the menu operation you get when not in "Edit Page Mode" and it simply hides the web part from view - SharePoint still attempts to load its assembly and you will get errors if there is no corresponding safe control entry.

If this is the problem then the easy way to delete it is to put ?contents=1 on the end of the URL and the page will open in Maintenance Mode.

Hope this helsp!

0
jkg0 On

Using reflector I found this is how they generate the GUID for each control:

internal static Guid GetTypeId(MD5HashProvider md5Provider, Type type, string assemblyName)
{
    byte[] bytes = new UnicodeEncoding().GetBytes(assemblyName + "|" + type.FullName);
    return new Guid(md5Provider.GetHash(bytes));
}

So if you really want to find it, run through every assembly and type and match the GUID. Good luck. I have the same problem. I plan on removing one control at a time until I pin down which one it is.