locked
How to add a "safe" webpart to site page? RRS feed

  • Question

  • Hello Community

        When you create a site there are WebParts that are available by default.  But sometimes
    you have to find a WebPart and run the stsadm commands:

    stsadm -o addsolution -filename <Solution filename> [-lcid <language>]

    stsadm -o deploysolution -name <Solution name> [-url <virtual server url>] [-allcontenturls]
    [-time <time to deploy at>] [-immediate] [-local] [-allowgacdeployment] [-allowcaspolicies]
    [-lcid <language>] [-force]

        After that you should be able to use the webpart on your site.

        So I created a web application and then created a site.

        Next I found "ToolbarManager.webpart" WebPart because it does not come with the site by default.

        Then I ran the above stsadm commands which ran successfully.

        But when I tried to add the Webpart to the site page I got the error message stating:

            "Unable to add selected web parts(s)."
            "Toolbar Manager: A Web Part or Web Form Control on this Page cannot be displayed or
                imported. The type is not registered as safe."

        To look into the problem I ran the gacutil.exe command which displayed:

        "The Global Cache contains the following assemblies:
            ToolbarManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8e586c4c8b123d97"

        Since the ToolbarManager is in the Global Cache there should be a way to register it as safe
    but the only other way I know of registering besides using stsadm.exe is in the web config.

        Usually the syntax to register safe controls in web config go something like this:

        "<SafeControl Assembly="[Assembly Name]" Namespace="[Namespace]" TypeName="*" Safe="True" />"

        The web.config is in the default port for the web application created at C:\Inetpub\wwwroot\wss\VirtualDirectories\80
    so I figure you can use the web.config in that port even though the port number isn't used
    in the url it is located at:

            http://severname/

        The site is located at:

            Servername/sites/sitename/default.aspx

        The problem is that if you want to use the web.config, according to the above syntax
    you need to know the "namespace" but the above gacutil.exe command does not display a namespace
    it only shows the assembly name,  the web application and site are urls so they don't show a namespace
    either.

        How can I get pass the error message and add the ToolbarManager.webpart to my site page?

        Thank you
        Shabeaut

    Thursday, January 12, 2012 10:01 PM

Answers

  • The solution should add the safecontrol entry for you.  If you are trying to add an existing web part from another site collection to this site collection look at the web.config for the web applicaiton that is currently using the web part.  You can find the right safecontrol entry there.
    Paul Stork SharePoint Server MVP Chief SharePoint
    Architect: Sharesquared Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.
    Thursday, January 12, 2012 10:25 PM
  • First Perfer Paul suggestion to find the namespace/config entry.

    if you are not able to find solution if you got the same result you try below  

    Remove the " ToolbarManager.webpart" from the web part gallery. add the safecontrol entry in the web config file. if you are not able to find the Namespace you may get in " ToolbarManager.webparT" in the metaData tag. you may read below link might be helpful, "http://msdn.microsoft.com/en-us/library/ms227561.aspx"

    Once you added the config entry. Deploy the assembly in the GAC. then do IISReset, goto web part gallery & populate the web part.  It will populate the "ToolbarManager.webpart" again into the web part gallery. 

    Hope this will help you deploy the web part.

    Friday, January 13, 2012 4:11 AM

All replies

  • The solution should add the safecontrol entry for you.  If you are trying to add an existing web part from another site collection to this site collection look at the web.config for the web applicaiton that is currently using the web part.  You can find the right safecontrol entry there.
    Paul Stork SharePoint Server MVP Chief SharePoint
    Architect: Sharesquared Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.
    Thursday, January 12, 2012 10:25 PM
  • First Perfer Paul suggestion to find the namespace/config entry.

    if you are not able to find solution if you got the same result you try below  

    Remove the " ToolbarManager.webpart" from the web part gallery. add the safecontrol entry in the web config file. if you are not able to find the Namespace you may get in " ToolbarManager.webparT" in the metaData tag. you may read below link might be helpful, "http://msdn.microsoft.com/en-us/library/ms227561.aspx"

    Once you added the config entry. Deploy the assembly in the GAC. then do IISReset, goto web part gallery & populate the web part.  It will populate the "ToolbarManager.webpart" again into the web part gallery. 

    Hope this will help you deploy the web part.

    Friday, January 13, 2012 4:11 AM