Pages

Wednesday, October 19, 2011

"Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges"..."Request failed"

When I tried running some code within the "Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges" block I received this exception message:

System.Security.SecurityException was unhandled by user code
Message="Request failed."
Source="Microsoft.SharePoint"
StackTrace:
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at JackBe.SharePoint.Core.Logging.SPLogger.Log(String message, CategoryID categoryID, TraceSeverity severity)
at JackBe.SharePoint.Core.Logging.SPLogger.Log(String message, CategoryID categoryID)
at JackBe.SharePoint.WebParts.MashletWebPart..ctor()
at T_27cf1440_c8a3_45ef_b04a_bcf1032711ed.CreateInstance()
at System.Web.HttpRuntime.FastCreatePublicInstance(Type type)
at System.Web.UI.WebControls.WebParts.WebPartManager.ImportWebPart(XmlReader reader, String& errorMessage)
InnerException:

It turns out the problem was I was executing this code too early in the page life cycle. I moved the block to "CreateChildControls" and the problem went away.

No comments :

Post a Comment

I always welcome constructive feedback. Thanks.