Archive for March, 2012

The application attempted to perform an operation not allowed by the security policy – DirectoryServices

I have developed a custom search and successfully deployed in our SharePoint 2007 (We have almost 16 sites and one document library, so we decided to filter the search according to the location, I will post the step by step development to the custom search later :)). My manager asked me to pick the location (ie. Organizational Unit (OU)) from Active Directory (AD) according to the user dynamically and I have written a method to pick the OU, you can see the post here. So far I didn’t get any problem but when I tried to deploy the web part to the SharePoint, I have got several errors and I managed to solve them but the following error gave me very hard time.

Security Exception: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type ‘System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ failed.

Source Error:

Stack Trace:

I tried several solutions to fix this issue but no luck, because my C# code is trying to access the AD information which is in the different server, so there is no trusted permission from SharePoint, but I could access the details form the local machine. Finally I just read the error message carefully and modified the Trust Level in the SharePoint web.config to “Full” then it was working.

Please note: Changing this Trust Level might harm your SharePoint Security!

To do the changes:

Step1: Open the web.config file (Using Notepad OR Visual Studio)

Step2: Locate the <trust level=”WSS_Minimal” originUrl=”” /> tag in the web. config file. The default value is “WSS_Minimal”. I tried “WSS_Medium” but it didn’t solve the problem, sometimes it will solve yours.

Step3: Change the <trust level=”Full” originUrl=”” />

That’s all, it is working now. Happy coding n SharePointing! There are some other solutions for this related issue, you can try.

1. Changes on the .NET Framework 2.0 Configuration tool, Tim Huffam’s blog will show how to do the work around.

References:

1. http://support.microsoft.com/kb/555466

2. http://us.generation-nt.com/answer/using-system-directoryservices-sharepoint-webpart-help-35022312.html

3. http://geekswithblogs.net/timh/archive/2006/03/08/71714.aspx

Advertisements

, , , , , , , ,

4 Comments

SharePoint search is not working, after moving the sites and the databases to the new servers

Recently we have moved our SharePoint intranet environment (MOSS 2007 and SQL 2005) to the new servers (Medium farm) because of the performance related issues. After moving the databases and sites, our team was doing some testing. I was trying to search a document and I didn’t get any results even we have done search setup and crawling already. 😦

One of my friends, who sent me this useful link which suggests the reliable search deployment! After configuring few additional set-ups including some Regedit (Windows Registry) modification, the search is working perfectly. YaY!

References:

1. http://blogs.msdn.com/b/agazzeri/archive/2009/04/16/sharepoint-server-2007-10-suggestions-for-a-reliable-low-latency-search-deployment.aspx

, , , , ,

Leave a comment

Turn on detailed error messages in SharePoint 2007 /2010

This is not really new but currently I am working on some customized web parts, so I need to turn on/off the detailed error messages when I need to fix some hectic problems on my development environment. There are many posts regarding this, but I wanted to keep my own post for my future references. 😉

Normally SharePoint shows custom error messages to the users such as “An unexpected error has occurred” but this is not going to help, so we need to know the detailed ASP.NET error message to fix the problem. Here are the steps to turn off custom error messages.

Step 1: Go to the SharePoint host server and navigate to the Virtual Directories folder. Normally this is available in this path “C:\Inetpub\wwwroot\wss\VirtualDirectories”

Step 2: Find the web.config and get the backup for the safety purpose

Step 3: Open the web.config file using Visual Studio OR Notepad

Step 4: Find the “CallStack” and change the value to “true” instead of “false”

Step 5: Find the “CustomErrors” and change the value to “Off” instead of “On”

Step 6: Save and close the web.config, refresh the page then you will get the detailed (wired) error message. Time to fix this huh? 🙂

Error message before turning on:

Error message after turning on:

MSDN reference shows the “CustomErrors” values can be one of these:

Value Description
On Specifies that custom errors are enabled. The custom errors are shown to the remote clients and to the local host.
Off Specifies that custom errors are disabled. The detailed ASP.NET errors are shown to the remote clients and to the local host.
RemoteOnly Specifies that custom errors are shown only to the remote clients, and that ASP.NET errors are shown to the local host.

If you want, you can also set the “CustomErrors” value to “RemoteOnly” to show custom errors only to the remote clients.

R./

References:

1. http://davidkvas.blogspot.com/2011/05/turning-on-detailed-error-messages-in.html

2. http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx

, , , , , , , ,

1 Comment

How to remove a corrupted WebPart from a page in SharePoint 2007

When I was playing with custom WebParts in SharePoint 2007, I used to getting an error message saying “An unexpected error has occurred“ and I could not navigate to the previous page again! Because SharePoint stores all the .aspx pages directly to the database, so when a corrupted WebPart added to the page we cannot access them!

Add a custom WebPart to the SharePoint page:

Unexpected error:

So you need to delete this corrupted WebPart to navigate to the page again. There might be several way to solve this issue, but following is an easy way to delete the WebPart! Here you go 🙂

Step 1: Just type “?contents=1” in the address bar to the end of the url and Press <Enter>.

You will be navigating to the following Web Part Page Maintenance page.

Step 2: Select the WebPart which you want to delete (OR whatever you want to do) and click delete link button on the top. That’s all you are able to navigate to the page without any issue!

Please note: If you change any other WebPart in the Web Part Page Maintenance page, it will be affecting all other users who have access this page!

R./

References: 

1. http://erichanes2008.blogspot.com/2011/10/remove-corrupted-web-parts-in.html

, , , , ,

1 Comment

WSP Builder Error 1 – Microsoft SharePoint Services Timer is not running on ”Server Name”

I was developing a Webpart using WSPBuilder (SharePoint WSP tool) in my new development server (SharePoint 2007, Visual Studio 2008 and Windows 2008 R2) and was trying to deploy the solution then I have got the following error message!

I have checked the “Windows SharePoint Services Timer” on the Windows Services and it was running! I tried to re-build and re-deploy the solution again and I have got the same error message again. 😦

Start –> Administrative Tools –> Services

After spending several minutes and I have found the solution here!

If we want to deploy a solution using WSPBuilder, it needs the Administrative privileges, so we need to run the Visual Studio as Administrator.

That’s it, I was able to deploy the Webpart successfully!

References: 

1. http://social.msdn.microsoft.com/Forums/ar/sharepoint2010general/thread/74aff7aa-ea97-4317-a4ba-41566cbe020a

2. http://pbodev.wordpress.com/2010/01/05/microsoft-sharepoint-services-timer-is-not-running/#comment-57

3. http://madtechnology.wordpress.com/2008/06/24/wsp-builder-for-sharepoint-microsoft-sharepoint-services-timer-is-not-running-error/

, , , , ,

1 Comment