SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the below code which I used to get the web reference using the title of the web site. The problem is the current user is not a member of all sub site so I'm getting access denied error.

User A have rights to: Web1, Web2 (no problem with code)

User B have rights to: Web1 (problem with code because he doesn't have rights to web2)

int projectid = GetProjectID(SPContext.Current.Web.Title, Url);

string projecttitle = SPContext.Current.Web.Title;

var nodename = currentWeb.ChildNodes.Cast<SiteMapNode>().FirstOrDefault(node =>
node.Title == projecttitle);
share|improve this question
On what row is the access denied coming from? If it is in GetProjectID method, please show us from what row in that. – Jussi Palo Feb 7 '12 at 7:24
var nodename = currentWeb.ChildNodes.Cast().FirstOrDefault(node => node.Title == projecttitle); – My Name is Suresh Feb 7 '12 at 8:09
Added an answer, but is there a reason (performance, perhaps) why you are using SiteMapNode)? – Jussi Palo Feb 7 '12 at 8:41
up vote 0 down vote accepted



to get only subwebs current user has access to.

If you want to get all sites even if user doesn't have permissions to access them, use SPSecurity.RunWithElevatedPrivileges:

    using (SPSite site = new SPSite(web.Site.ID))
    // implementation details omitted
share|improve this answer

Use SPSecurity.RunWithElevatedPrevileges. The code inside the specified delegate will then run under the identity of the current app pool user.

share|improve this answer

Your Answer


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.