SPContext.Current.Web.CurrentUser null in application page on 2008 r2 server
With my current situation I have:
a wss3 development environment on a 2003 R2 server
then a production 2008 r2 server.

For some reason on the 2008 server the SPContext.Current.Web.CurrentUser object is null for users who are site collection administrators but may not have permission to log into the server itself; however, on the 2003 R2 server the code works fine for those users.
When googling around, I had seen something about nt permissions on the bin folder sometimes being and issue until asp.net cache picks up the dll but this is a page in the _layouts directory and the code is in the .aspx page itself. It works fine for me as a system administrator on either machine.

Any suggestions? Thanks.
  • Moved by Wayne Fan Thursday, October 14, 2010 7:29 AM It's SharePoint 2010 issue, thanks. (From:SharePoint 2010 - Using Visual Studio with SharePoint and other programming)
October 12th, 2010 7:22pm

It dawned on me that the admins having issues might be already logged in and operating from a url with the computer name and then clicking a link to a tool in the _layouts folder but that link was using an alternate access mapping url--a FQDN. After having them keep consistent root URL it worked for them. I guess at this point though is there a way to keep them logged in when switching? Or is there a way to force users that log into the computer name based url to then be redirected to the FQDN url for the sharepoint?


Free Windows Admin Tool Kit Click here and download it now
October 12th, 2010 9:43pm

Way later, but here is another way to deal with this issue.

Once you realize that the CurrentUser == null, you need to add this line of code:

Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(new UnauthorizedAccessException());

This forces SharePoint to go through whatever authentication mechanism is configured, and if a redirect is not involved (such as challenge/response) then on the next line of code, the Microsoft.SharePoint.SPContext.Current.Web.CurrentUser property will be filled in correctly.

December 11th, 2014 7:35pm

Wow, I don't know where you discovered that trick because I couldn't find it anywhere but here. I had the same problem intermittently in my IHttpHandlers (<g class="gr_ gr_171 gr-alert gr_spell ContextualSpelling ins-del multiReplace" data-gr-id="171" id="171">ashx</g>) and putting that in fixed it right up when the CurrentUser was null. Thanks.
Free Windows Admin Tool Kit Click here and download it now
March 6th, 2015 1:49pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics