SharePoint Permission problem when programming Object model with trust level WSS_Minimal
Posted on 2/27/2008 11:28:14 AM
in #SharePoint
Hi,/P>
/o:p>/P>
Last few days I was playing with SharePoint server 2007 and programming with it. All I was trying to do was add a list item in a simple list created in the SharePoint through a web part. The code to do the job was simple enough./P> SPWeb site = SPContext.Current.Web;/o:p>/SPAN>/PRE>SPList list = site.Lists["Vikram Site List"];
SPListItem newItem = list.Items.Add();/o:p>/SPAN>/PRE>newItem ["Title"] = "http:////www.VikramLakhotia.com";/o:p>/SPAN>/PRE>newItem.Update();/o:p>/SPAN>/PRE>
But when I deployed the code it started giving me Permission error. It was very difficult to know from the error itself on what was the actual problem. The actual error was /P>
/o:p>/P>
Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, ' Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed./P>
/o:p>/P>
I could not follow what problem can be there with permission in the line of code that I wrote. Later on googling the error code I found that the error was caused if you are running the SharePoint application with security policy WSS_Minimal. To be able to program against SharePoint Object model we need to change the security policy to WSS_Medium. This can be done by changing the trust level in the web.config file./P>
<trust level="WSS_Minimal" originUrl="" //>/P>
to /P>
<trust level="WSS_Medium" originUrl="" //>/P>
This will solve the problem. Also note the medium trust level policy allows you to program against SharePoint object model and access NT event log./P>
Vikram/P>
|