I am using the below code to access the web-application from sharepoint.
SPWebApplication webApplication = SPContext.Current.Site.WebApplication;
it works fine with the sharepoint server 2010(MOSS2010). But when I work with SharePoint foundation 2010(WSS4.0) SPContext.Current always returns null. Can anyone tell me what could be the reason for this? and how can i resolve this issue?
Thanks and regards,
Sharmila
One of the common reasons I’ve seen where SPContext is found to be null is when you have an incorrectly configured AAM. Its really important that sharepoint understands what URLs are configured for your site because if your URL is not registered it cant tell if the URL is inside the SPContext hence create it.
Take a look here if you want to know how to setup AAMs (and find out why they are so important) take a look at my blog post on the subject
http://blog.staticvoid.co.nz/2011/05/sharepoint-alternate-access-mappings.html