SP2010 Update Site Title and Description - Security problem
-
06-12-2019 - |
Pregunta
I've created a custom application page to update the Title and Description of a site. The page is generating an access denied and the following error message in the log file:
Unknown SPRequest error occurred. More information: 0x80070005
using (SPSite SiteCollection = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb UpdateCurrentweb = SiteCollection.RootWeb)
{
UpdateCurrentweb.Title = SiteTitle.Text.ToString();
UpdateCurrentweb.Description = SiteDescription.Text.ToString();
UpdateCurrentweb.Update();}}
Adding:
SPSecurity.RunWithElevatedPrivileges(delegate() { });
or
UpdateCurrentweb.AllowUnsafeUpdates = true;
UpdateCurrentweb.AllowUnsafeUpdates = false;
Is NOT resolving the problem.
Solución 2
The solution for the initial question was the location of the SPSecurity clause. After putting it outside the using statements it worked fine! The purpose was to update the Root Web but the remark of James is very valid as well! –
Otros consejos
Do you realise that that code statement will update the Root Web of the site collection, no matter what level of website you're in. Think you might want to try SiteCollection.OpenWeb()
in your second using statement, instead of SiteCollection.RootWeb
. This will let you set the title and description of the current website in question (unless it's your intention to do otherwise).