I have been getting the following error for only some users, and on some pages that has a web part that I created that checks for their username information.
403 Forbidden – The website declined to show this page, most likely cause, this website requires you to log in
Yes, I tried logging out and logging back in. I have tried everything….
Here is my code:
Microsoft.SharePoint.SPSite site = Microsoft.SharePoint.SPContext.Current.Site;
Microsoft.SharePoint.SPServiceContext context = Microsoft.SharePoint.SPServiceContext.GetContext(site);
// Uses the profile manager that was set up in Central Admin
Microsoft.Office.Server.UserProfiles.UserProfileManager profileManager = new Microsoft.Office.Server.UserProfiles.UserProfileManager(context);
if (impersonate.Length == 0)
// Used this, but there is no difference: staffMember = SPContext.Current.Web.CurrentUser.LoginName.ToString();
// Used this, but there is no difference: staffMember = System.Web.HttpContext.Current.Request.ServerVariables["AUTH_USER"];
staffMember = HttpContext.Current.User.Identity.Name;
staffMember = impersonate;
Regardless of the different combinations I tried, I got this error only for some users, and only on some of the pages. So far my trend has only been the web part I created with this code. If I bypass that code (and I have a query string that allows me to impersonate a user) it will work just fine
Here is the error:
So after about 8 hours of troubleshooting, I finally figured out it would work just fine if I added that user that was having issues to the Administrators Group on the local SharePoint server after performing an IISReset.
So, after playing around a bit more I added “NT Authority\Network” (a local account) as a local admin instead of the user that was having a problem, performed an IISReset, and it worked as it should now for that user and all of the affected users.
I am waiting to hear back from Microsoft to see if this is a recommended solution to the issue, or if there is a better practice solution that I should be following.
I will keep this post updated.