I'm inheriting an ASP.NET application that is hosted within the IIS SharePoint web site. From IIS, right click the Web Site, and click 'Add Application' is the method used here.

In our dev server, where the 'owner' of the application set it up, SPContext is being populated as we would expect. However, in production, SPContext is null.

I have also created my own test SharePoint Web Application, and I added a standard Visual Studio ASP.NET Web App into this to test the SPContext issue...Unfortunately SPContext is null.

DEV Server

Existing App : SPContext != null

Test App : SPContext == null

Prod Server

Existing App : SPContext == null

Test App : SPContext == null

What am I missing that it takes to get SPContext populated? I've tried SPContext.GetContext(HttpContext.Current), but SPContext.Web is null then. Ideas?

1 Answer 1


Immediately after posting this, I had an idea. None of the web applications that are failing have a "Root" site collection. Technically there is no such thing as a root site collection, but I created one in the Prod Server > Existing App (at the '/' managed path) and things magically started working.

So it seems that SPContext somehow is defaulting to WebApplication.Sites[0]

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.