How to identify an unsafe web part / control - sharepoint

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?

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!

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.

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.

Related

Kentico 10 - Web Part content change via database

i was trying to understand in the Kentico's database model how can i change the web parts content using a database script.
So, basically i have a website based on Kentico with several articles, and internal hyperlinks in its content. But the problem is that the format of those hyperlinks are actually invalid. And i was looking for a way to build a script and do a bulk-update in order to replace some characters and update those hyperlinks to the valid format.
Any idea how can i build the query to get the content of all web parts used in all published pages.
Thank you
It depends on your web parts and how the content is rendered. There are different ways that web parts render their content:
The web part layout is used for markup
The ASCX file for the web part is used for markup
The web part makes use of a repeater that uses a Transformation to render the markup- The markup is generated in code behind
The last one can be tricky to change depending on the web part and whether you have access to all the code behind, but the others you can change either in code in your solution or within the Administration area itself.
Doing this in SQL would probably require a combination of T-SQL XML support and regular expressions to find what you're looking for. you effectively need to look in the CMS_WebPart and CMS_WebPartLayout tables to find what you're looking for.
However, reading your query, I'm not 100% sure you're talking about web parts, (my apologies if you are) as you talk about links in the article content itself. If these are set using the Editable text web part, then you need to look in the CMS_Document table at the DocumentContent field to find the links to replace. But you then need to look at how to correctly format those links going forward so that you do not need to repeat this process later.
Note:
You need to be really careful when doing this in SQL to make sure that you don't create invalid XML. Things go bad when you do that.
This won't flush your cache, so you'll need to clear your cache manually afterwards.
If you're using out-of-the-box web parts, you should really make a copy of them and use the copy if you're going to modify, this way, you're less likely to have pain in future upgrades.
Typically "content" is not set in a webpart. Webparts are configured to retrieve content from page types. There is an exception to this with specific webparts like Editable Text, Static Text, Static HTML, etc.
The configuration of a webpart is stored at the template level in the cms_pagetemplate table. The configuration for ALL webparts on that page template are stored in the PageTemplateWebParts field. So you'd have to parse through the XML and get the proper webpart and then perform an update on that field. You maybe able to do a regex to find that content and replace it as well.
Not ideal to do this via SQL simply because of version history and it can cause a lot of problems later on. I'd suggest finding out which API calls you can make to perform these updates and write a small program for it.

View. Show values as Links. Strange behaviour

Xpage (listPostits.xsp) has a "View" container control, where one of the column is set "show values in this column as links".
Now, here comes "Strange behaviour".
When i work with this application on my own (developer) PC (Win XP, Chrome or IE), the Domino generate the link, which can't be really processed:
/servername/db/postit/postit.nsf/listPostits.xsp/onePostit.xsp?documentId=many_numbers&action=editDocument
Namely, the Bold-marked portion shouldn't be there ! This portion is the name of the XPage, where the View control is in.
When i work with the application from other PC (Mac, Firefox) then i get the correct link (the same as above but without the XPage name inbetween):
/servername/db/postit/postit.nsf/onePostit.xsp?documentId=many_numbers&action=editDocument
update: let us leave for the moment the differencies in generated links between two machines. The first question is - why the extra portion is inserted into automatically generated link?
After playing around i think i might have found the reason for this strange behaviour. Namely, the "Substitution" Rules on the server side. One of them is to substitute "*/postit/all" with "/db/postit/postit.nsf/listPostits.xsp"
If i switch it off, then the Links are generated properly. Still, it's pretty strange to me that these settings influence the way Domino generates the links. I thought it works on the fly with them and those settings have nothing to do with the way how Links are generated inside the application.
So, the help now is needed regarding Web Site Rule Topic, but for that, i guess, i have to create another topic. But in case somebody has some good Info on this, please share it with me. I'm a bit confused at the moment :)
Final Update: Spent some more hours of testing and the results confirmed the initial idea.
If i open the page with the standart URL, i.e.
http://servername/db/postit/postit.nsf/listPostits.xsp then everything is fine, links are generated properly. When i however open the same page with short URL http://servername/postit/all , then server adds the substitute URL (db/postit/postit.nsf/listPostits.xsp) to every single link he generates automatically to be used as the link to open/edit the underlying document.
Is it bug or feature ? Don't know.
As a workaround (because i want to keep simple URL's for the application) i have to manually generate links.

SharePoint 2010 Error when creating list view

I have a custom list definition created via visual studio 2010. I would like to create a calendar view of this list using the web interface. When I attempt to create the view however, I am greeted with a helpful error message of:
Error
Cannot complete this action.
Please try again.
About the problem:
When I attempt to duplicate this error while running Fiddler2, I see a response of 404 Not Found when attempting to access /_vti_bin/owssvr.dll?CS=65001 using the HTTP POST verb.
No errors are logged in the ULS logs.
If I create a new custom list and attempt to reproduce the issue by adding two date columns and creating the calendar view, everything works as expected.
The schema.xml file defining the list is fairly large, with close to 25 fields.
I am using custom templates for the new, edit, and display forms.
I have defined a new custom view showing a subset of the columns in schema.xml
Does anyone know of any "gotchas" or things to look for in my list definition that could be related to this issue at all?
Has anyone encountered this issue before, and know of a way to fix it?
Failing those, what more can I do to debug this?
To avoid overflowing this question with large code blocks, you can view my list definition here:
Elements.xml - http://pastebin.com/97ucAedZ
Schema.xml - http://pastebin.com/2brpMJgT
ListInstance Elements.xml - http://pastebin.com/gnCXVpmh
I agree with moontear. I think your Content Type ID is invalid. If you are building off a Custom List template, I would expect your Content Type ID to be:
<ContentType ID="0x0100781A2C74BF4bfd81AE710DB1EACAE745"
Name="$Resources:Item"
Group="$Resources:List_Content_Types"
Description="$Resources:ItemCTDesc"
Version="1">
To inherit from Item, you should have 0x01 then 00 followed by a Guid. You have the right number of characters, if you use 00 instead of 70.
For more information, see Content Type IDs.
In cases like this, i usually take these steps:
Create List/View manually in MOSS.
Export list as template and try to
find out what is wrong in my
template.
Start with clean template, add one field etc at a time, test, repeat until error emerges.
Your xml seems ok, so i think it will be another MOSS 'gotcha' or 'aha' moment.

Determine the property name in a SharePoint Webpart for XML

I'm employing a custom webpart that is made by an unaffiliated third party. I've created a feature which adds this webpart to a page. It's working mostly fine, except that I can't figure out the name of a specific property that needs to be defined. I tried obvious ones that match the display name on the tool pane view, adding the company's name in front of said display name, and many similar permutations. All of which to no avail. I would much prefer to include the property to the feature, as this will be necessary to deploy across multiple sites in the future. Manually configuring it every time will be a pain for my client.
The short, obvious answer is "Ask the third party". This can potentially work, particularly for this specific one (it is a CodePlex webpart and the author has posted a comment as recent as last week). But my experience with previous third party solutions has been less than optimal, usually even getting no response until they ask me three weeks later if I still like their product. So, since this is not always a reliable method to obtain this information, I was thinking the best option is to find out a way to figure out the name of properties in a webpart that I can use not just with this particular one, but in all future situations.
I did check out this earlier question which addresses a similar topic. However, I don't have access to the class for the webpart so I can't just find a convenient property in the code to modify. Or, at least, if I do have access to it in some fashion, I'm certainly unaware of it.
Thank you in advance!
From what I understand, you are trying to set a certain webpart property for which you do not know the corresponding XML attribute name.
Did you try to export the web part? One possible check might be to try to export the webpart to see what properties come up in the webpart XML. If it is a common property, chances are the webpart XML will have that property already defined with no value e.g.
<data>
<properties>
<property name="Your property Name" type="yourType"></property>
<properties>
</data>
To export the webpart, go to Edit Page mode, click the down arrow on the webpart and choose Export.
Also, if you have the webpart code in a dll, can you use reflector to open it and see what properties are being set in code?
Hope this helps.

SharePoint SPContext.List in a custom application page

I have a custom SharePoint application page deployed to the _layouts folder. It's a custom "new form" for a custom content type. During my interactions with this page, I will need to add an item to my list. When the page first loads, I can use SPContext.Current.List to see the current list I'm working with. But after I fill in my form and the form posts back onto itself and IsPostBack is true, then SPContext.Current.List is null so I can't find the list that I need to add my stuff into.
Is this expected?
How should I retain some info about my context list across the postback? Should I just populate some asp:hidden control with my list's guid and then just pull it back from that on the postback? That seems safe, I guess.
FWIW, this is the MOSS 2007 Standard version.
Generally speaking I try and copy whatever approach the product group has taken when looking to add functionality of my own. In this case they add their own edit/view/add pages via the list definition itself.
I built a solution that also needed its own custom "New" form, not open source unfortunately, though if you are interested you can download it, its called "Tagged Links" (Social Bookmarking for SharePoint) and you can find some links on my blog.
To give you a few hints and tips, the following should set you off in the right direction:
Created a new list definition.
Created a new Content Type In the content type you can define your own "FormTemplates" that references a Rendering Template which determine what gets displayed in the "Middle" bit of those forms.
Copied the standard Rendering Template, but then made the changes to it that I
needed.
Wrapped it all up in a solution, and deployed.
My Rendering Template actually included an overridden "Save" Button where I did a lot of the extra work I needed to do during the save.
Anyway, it is a little too much work in my opinion but, I think, it most closely matches the standard approach taken by the product developers. Let me know if you need more detail and I will see if I can put together a step-by-step blog post, but hopefully this gets you off on the right direction.
I would be surprised if you could do something in a _Layouts file that you can't do in a forms template. You have pretty much the same technologies at your disposal.
Looking at the way SharePoint works with ListItems and Layouts pages (for example "Manage Permissions" on a list item), I can see that they pass some variables in via querystrings:
?obj={76113B3A-FABA-4389-BC85-4BB2CC5AB423},6,LISTITEM&List={76113B3A-FABA-4389-BC85-4BB2CC5AB423}
Perhaps they grab the context back each time programmatically using these values.
I'm not using a custom "new form", so this might not apply. I added an event receiver to my custom content type and then do my custom code in the ItemAdded or ItemAdding events. This code fires when the event is added to a list. You can use the event receiver properties to get to the parent List, Web, and Site.
I'd like to think my issue is "special" here, since I am using a custom form. I chose to use a custom form rather than a custom FormTemplate simply because I'm doing a lot of stuff that's not very SharePoint list-like (making ajax calls to get info from a third-party app then generating some dynamic form elements based on that ajax result, then subsequent processing of that data on postback). I thought it'd be a nightmare to try this within the usual custom rendering template mechanism.
I also don't think I can supply the custom form declarations in the list definition itself, because I have multiple content types associated with this list, and each content type has its own custom form (the other type is thankfully much simpler).
Actually, my simple way of keeping the list guid in my hidden field was a very low impact way to address this specific problem. My main concern is that I'm not sure why the SPContext just loses all its usefulness when I postback here, which makes me think I'm doing something wrong.

Resources