I have been tasked with modifying a custom access denied page (SharePoint 2013) I built a year ago. The page was built in Visual Studio 2015 and contains C# code behind. I was asked to add the Site Title to the page. Simple I added lblTitle=SPContext.Current.Web.Title.ToString() to my code behind and display it in my aspx page.

Works great except that it only works for people who at least have View permissions to the site. If a user who has no rights to the site they get redirected to the access denied page then they get a 403 error. I have determined that it is the call to the site title that is causing this. I have tried getting the site title with elevated privileges but that did not resolve my issue.

So my question has anyone displayed the site title on the Access Denied page before? If so how did you do this. Can it be done with C# or JavaScript from my existing custom page?

Any suggestions appreciated.

1 Answer 1


Elevated permission will solve this issue. Make sure you create SPSite and SPWeb in the context of elevated scope as below

     using (SPSite site = new SPSite(siteURL))
        using(SPWeb web = site.OpenWeb(webURL))
  • I tried this but it is not working I still get "UnauthorizedAcceeException".
    – Moe
    Oct 27, 2017 at 20:02
  • Can you share the relevant code Oct 27, 2017 at 20:02
  • SPSecurity.RunWithElevatedPrivileges(delegate () { using (SPSite site = new SPSite(SiteURL)) { using (SPWeb web = site.OpenWeb()) { label1.Text = SPContext.Current.Web.Title.ToString(); foreach (SPRoleAssignment roleAssignment in web.RoleAssignments){do some more stuff} } } });
    – Moe
    Oct 27, 2017 at 20:12
  • Why are you still using label1.Text = SPContext.Current.Web.Title.ToString(); SPContext? you should use web.Title Oct 27, 2017 at 20:14
  • Ah Thank You I think I got it! label1.Text = web.Title;
    – Moe
    Oct 27, 2017 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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