Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SharePoint > SharePoint Development
SharePoint Development Programming 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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 18th, 2009, 01:38 PM
tnk tnk is offline
Registered User
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with RunWithElevatedPrivileges

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.

                string s;
                s = "something";
That just gives the error:

System.Security.SecurityException was unhandled by user code
Message="Request failed."
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)

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.

Any help is greatly appreciated.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.