Developer forum

Forum » Development » User Save() error

User Save() error

Keld Lauge Gøtterup
Reply
im making an Ajax call to an ashx page where i need to change which group a user is located in.

in the ashx file i make a call to the following function:

public static void Valid(int id)
        {
            User current = User.GetUserByID(id);
            if (!current.HasGroup(6143420))
            {
                current.AddToGroup(6143420);
                current.RemoveFromGroup(6143422);
                current.Save();
            }

        }
but that unfortunately results in an error however the user actually gets transferred into the right group.


[NullReferenceException: Object reference not set to an instance of an object.]
   Dynamicweb.Modules.UserManagement.User.get_Current(PagePermissionLevels level) +431
   Dynamicweb.Modules.UserManagement.User.Save() +201
   CvrChecker.Helpers.Valid(Int32 id) +203
   CvrChecker.CheckCVR.ProcessRequest(HttpContext context) +2179
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +624
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +269

Replies

 
Vladimir
Reply
This post has been marked as an answer

Hi Keld

Try to add the IRequiresSessionState interface in your handler (it has no methods, it's just a marker interface to tell ASP.NET that your handler relies on session state).

 
The code tries to get access to the Session object after it performs saving but isn't has access to do that

Best regards,
Vladimir

 

 

 

 

Votes for this answer: 1

 

You must be logged in to post in the forum