locked
Problem with webpart as a safe control RRS feed

  • Question

  • Hello

    I have stumbled in a proble I can't get over. It is basically very easy done that many times and yet I feel like I am missing some important point.

    Now: I have two web applications on same server and some webparts done by a company. One web application works fine with those webparts and other doesn't. I have copied the web.config contents regarding the company from the first one to the second. As a matter of fact it worked last night OK, but now in the morning it doesn't. I have re-copied the web.config partly and run iisreset and still no-go. This is really frustrating as I can't figure out where the problem lies and it keeps me quite uncertain even when it happens to work as how long it will work.

    Is there something I am missing? Something to make feel a bit more secure?

    best regards

    hank

    P.S. After I wrote this question, it seems again to work but I send this anyhow as I would like to know how could I get SP to work rationally and trustworthy :) This is not the first time this flip-flap has happened and though it seems to calm down after a while, I still don't like the uncertainty and doubt I get from this "feature"

    Monday, March 14, 2011 6:57 AM

Answers

  • Hi,

    it looks like you havent deployed the webpart with full CAS trust.

    in web.config locate

    <

    trust level="WSS_Minimal" originUrl="" /> 

    Change the Level to WSS_Medium provided these tags are present in web.config

    <securityPolicy > 

    <trustLevel name="WSS_Medium" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\wss_mediumtrust.config" />

    <trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\wss_minimaltrust.config" />

    </securityPolicy>

    Hope this helps.

    • Marked as answer by KeFang Chen Monday, March 21, 2011 5:11 AM
    Friday, March 18, 2011 8:50 AM

All replies

  • Hi szd55,

    You should not have to be manually editing the web.config file yourself, the WebPart WSP file should contain a Manifest.xml file which contains the element to put into the web.config for you when the solution is installed i.e

     

      <Assembly Location="MyProduct.dll" DeploymentTarget="GlobalAssemblyCache">
    
          <SafeControls>
    
            <SafeControl Assembly="MyProduct, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2c17e97d8cff3b5a" Namespace="MyProduct.MyProductWebPart" TypeName="*" />
    
          </SafeControls>
    
        </Assembly>
    

    How are you installing the Web Part?

     


    Lightning Tools – The Company where I work.

    BCS Tester Man the BCS Test Client – My Personal Project on CodePlex

    Monday, March 14, 2011 9:16 AM
  • I'm not sure why it works once and then not again.  In the web.config there are different security controls which need to be set.  If you have a copy of this server in Dev you can try changing some of these settings and see if it effects your out come.  SharePoint sets up security on what code can run with what is called Code access security. You will see this is set in the web.config file in what is called 'TrustLevel' there are two default securities set in the web.config file. YOu can either create your own or (not best practice) set it to Full.  This is commonly done to test and get the web part/application page working.

    Here is a link to creating a Code access security (CAS).

    http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/11/20/deploying-a-web-part-with-code-access-security-in-visual-studio-2010-sp2010.aspx

    Also a 2nd question is where is the dll registered.  Bin or GAC.  Sense you are using this on multi web apps.  I would register your dll in the GAC (Globel Accembly Cache).  THis si found in C:\Windows\assembly you will see the pubic key token for the dll and elements of what is called teh 4 part name.  This 4 part name must be place in what is called <SafeControls> section of the web.config file. The 4 parts to the name are Assembly, Version, Culture and PublicKeyToken. These should be exactly as listed in the GAC.  You can only get this in the GAC when they have a public key token.  YOu can have these signed in Visual Studio.  Here is an example of what this looks like.

    <SafeControl Assembly="System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="System.Web.UI.WebControls" TypeName="*" Safe="True" AllowRemoteDesigner="True" />

    Here is a blog that gives a good overview of this deployment steps.

    http://blogs.solidq.com/sharepoint/Post.aspx?ID=58&title=Creating,+Installing+and+Configuring+SharePoint+Controls+(WebControl,+GAC,+web.config,+SafeControl,+Register)

    Good luck,

    Gary


    Gary Newman MCSE, MCT, CCNA MCDBA, MCAD, MCSA MCTS SharePoint 2007 Dev & Admin MCPD SharePoint 2010 Development
    Monday, March 14, 2011 1:56 PM
  • Hello Phill

    Actually the software developer company has installed it on the _server_, but it should have been done OK. I have only deployed the web part (plus other features) in my web template for the site collection..

    I will check this tomorrow, anyhow.

    Best regards

    hank

    Monday, March 14, 2011 4:01 PM
  • Hello Gary

    It has been installed on the GAC. I am quite OK for the basic operation and assembly and I checked the values from GAC (and they DID co-incide with the ones in the web.config).

    Thanks for the pointer though :)

    What makes me most irritated is that I set it up - it doesn't work. I do something in-between and then (without at least knowingly doing anything connected) it starts to work - only to find next morning again that it doesn't work... after some little gymnastic I get really carried away and start venting it here and after having completed my post it again starts working...

    According my experience it sticks and keeps working from now on but this was not the first time that something made the system to click-clack between working and not working.

    Well... I probably just got to gather more information and maybe some day it all lightens up :) or then again, maybe not ;)

    But thanks a lot, anyway :)

    hannu

    Monday, March 14, 2011 4:08 PM
  • Hi szd55,

    Did you copy the web.config from first application to the second application?

    I don't think it's good idea except that you can make sure that the two applications are absolutely the same.

    And you'd better post the error message so that we can do research according to the error message.

    If you can't get detail information, you can change the mode of custom error to 'Off' with the following code.

    e.g.

    <System.Web>
      <customErrors mode="Off"></customErrors>
    </system.web>
    

    If you meaned that the error message was as the following message:'the ??? web part wasn't registered as safe control'.

    It means that you add one web part to your page while it's not registered as safe control in web.config.

    So you can do it as Phill suggested.


    Microsoft Online Community Support
    • Marked as answer by KeFang Chen Monday, March 21, 2011 5:10 AM
    • Unmarked as answer by KeFang Chen Monday, March 21, 2011 5:11 AM
    Tuesday, March 15, 2011 5:44 AM
  • Actually I only copied the relevant part of the Safe controls in web.config - naturally not fully. As the sites were the original and the copy of it, they should have been exactly the same in that regard. I think I have and had it right but in the beginning it just works or not and then the ripple diminishes are it starts working... just to reappear on another site/site change situation :/

    The error message was just the standard popup claiming that the web part isn't registered safe (or later the error message stating it (when I forst was able to add the webpart but later sharepoint "discovers" that , hey, this doesn't really belong here.

    But the bottom line is that though I have the right web.config which states the exactly same public key token and everything there is a error message (or popup) that says no-no. But as I have repeated, it just starts to work after some hiccups and thence works.

    hank

    Tuesday, March 15, 2011 11:39 AM
  • And now it has done it again...

    It seesm the only way to get itr working is to copy the safecontrols block (part of it) from the working site, run IIS, get mad, and finally write here and then maybe, just maybe it starts working.

    So..to list the things down:

    1. I have a site that seems to be working OK (which originally just a copy of this site) regarding some web parts

    2. With the "important" site on the very same server (QA) I get every now and then a problem that states that the very same web parts are not registererd as safe.

    3. I have copied the relevant part of SafeControls from the working site to not-working site, saved the web.config, run IIS and yet the problem persists. I am about to become (even more) insane as I can't understand where the problem lies. After trying everything except my sister (that I don't even have) It may find the web part as safe... just to change the mind after some day(s)

    Now...what could be the reason for such a "fun"

    hank

    Friday, March 18, 2011 7:06 AM
  • Hi,

    it looks like you havent deployed the webpart with full CAS trust.

    in web.config locate

    <

    trust level="WSS_Minimal" originUrl="" /> 

    Change the Level to WSS_Medium provided these tags are present in web.config

    <securityPolicy > 

    <trustLevel name="WSS_Medium" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\wss_mediumtrust.config" />

    <trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\wss_minimaltrust.config" />

    </securityPolicy>

    Hope this helps.

    • Marked as answer by KeFang Chen Monday, March 21, 2011 5:11 AM
    Friday, March 18, 2011 8:50 AM
  • I made the change. Of course the site had started working in meantime, but it kept working afterwards as well :)

    Now just waiting to see if it keeps going :)

    Thank you

    hank

    P.S. Still..the other site works fine with WSS_Minimal setting :)

    P.P.S. What makes me most uncertain is the sporadic nature of the problem...sometimes it works and then again not.

    Friday, March 18, 2011 8:59 AM