0

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

Regards.

1
  • 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

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

Try the code below instead:

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

    } 
});

for further info look here:

Microsoft.SharePoint.SPSecurity

it contains a method called RunWithElevatedPrivileges

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.