p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > SharePoint > SharePoint Development
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 18th, 2009, 02:38 PM
tnk tnk is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.

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.

Any help is greatly appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump



All times are GMT -4. The time now is 05:22 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc