SharePoint DevelopmentProgramming and development for SharePoint Portal Server and Windows SharePoint Services
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SharePoint Development section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
I can't get it to work...at all. Anyone know why? I am using WSS 3.0 SP1 with the Visual Studio 2008 WSS 1.2 Templates. I'm trying to make a web part feature that displays what sites a user has access to in the current web application (or virtual server as some people prefer). The code is quite simple but I am running up against security issues that I do not understand. I have spent considerable time scouring the web researching the issues at hand here and am still not able to solve my problem, which is rare.
At least one of my problems is even with no SP code in it, I cannot elevate my privileges.
Code:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
string s;
s = "something";
});
That just gives the error:
System.Security.SecurityException was unhandled by user code
Message="Request failed."
Source="Microsoft.SharePoint"
StackTrace:
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPri vileges(CodeToRunElevated secureCode)
at YourSitesWebPart.YourSites_WebPart..ctor()
at T_31ecb99f_3245_4cea_b13f_c404fd6fd0c0.CreateInsta nce()
at System.Web.HttpRuntime.FastCreatePublicInstance(Ty pe type)
at System.Web.UI.WebControls.WebParts.WebPartManagerI nternals.CreateObjectFromType(Type type)
at System.Web.UI.WebControls.WebParts.WebPartManager. ImportWebPart(XmlReader reader, String& errorMessage)
InnerException:
This is not helpful. My research has turned up all kinds of issues. Some people solve the problem by simply changing the trust level of the web app to "WSS_Medium". Others have to increase it to "Full". Others say this is bad form and that you need to make a custom CAS (Code Access Security) policy file, which I understand to just be some XML that I need to stick into my manifest.xml file with the feature. I also learned that using the SPSite and SPWeb classes means I need to call the .Dispose() method on them and be aware that these classes use unmanaged code and that I must take responsibility for dealloc-ing. No problem. I just need to figure out what the hell I need to do to fight through these security issues.