Take the 2-minute tour ×
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

Regards.

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
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

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.