Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to open site(FBA enabled with custommembership & customroleprovider) through module/httpmodule. It is throwing error

System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.SPSecurity.GetRolesForUser(String roleManagerName, String userName, UInt32& roleCount, String& roles)

Here is the code:

HttpRequest r = HttpContext.Current.Request;
using (SPSite s = new SPSite(r.Url.AbsoluteUri))
                    { ......}

Please provide me if there is any solution


share|improve this question
I dont know your exact usage, but is it possible to run your code under admin privilege like SPSecurity.RunWithElevatedPrivileges ? – Diptarag Oct 10 '12 at 8:30

1 Answer 1

Diptarag is correct if the user doesnt have access then it will throw that error:

Try the code below instead:

    HttpRequest r = HttpContext.Current.Request; 
    using (SPSite s = new SPSite(r.Url.AbsoluteUri)) 


for further info look here:


it contains a method called RunWithElevatedPrivileges

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.