Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
Hi, why don't you use default /_layouts/prjsetng.aspx page ? –  Alexander Oct 24 '11 at 13:58
1  
I assume that the SiteCol variable in the second using statement should be "SiteCollection" right? Otherwise you would be breaking elevation by using an instance that has been created outside the RunWithElevatedPrivileges privileges. Can you please confirm that? –  SPArchaeologist Oct 24 '11 at 13:59
    
SPArchaeologist: correct that was a typo –  Wim Hill Oct 24 '11 at 14:16
    
Alexander, my page is doing more than just adjusting title and description but only fails on this particular part of code... And needs to be run by a non site collection admin! –  Wim Hill Oct 24 '11 at 14:18
3  
Where are you placing the SPSecurity.RunWithElevatedPrivileges()? It needs to be outside of the Using statements, not merely around the three key lines of code. –  Dave Wise Oct 24 '11 at 14:48

2 Answers 2

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).

share|improve this answer
    
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! –  Wim Hill Nov 21 '11 at 7:38
    
Also, don't dispose RootWeb, think I saw a discussion on this somewhere else on this site recently (will be on the first couple of pages somewhere)... –  James Love Nov 21 '11 at 7:50
up vote 0 down vote accepted

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! –

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.