Try our conversational search powered by Generative AI!

Switching user context within a scheduled job



Does anyone know of a way to safely switch the context of the current user within a ScheduledJob on EPiServer 4.62?

We're using:

loginResult = EPiServer.Util.LoginBase.Login(username, password, false); 

However, this is producing a NullReferenceException.  I suspect this is being caused by a lack of HttpContext, but I don't know.

 Any  advice gratefully received!

Best Regards,


May 20, 2008 11:36

Here is some code, I hope it will help 

System.Web.Security.Membership.Provider.ValidateUser(username, password);

if (isValidUser)
MembershipUser mu = System.Web.Security.Membership.Provider.GetUser(username, true);
EPiServer.Security.PrincipalInfo.CurrentPrincipal = EPiServer.Security.PrincipalInfo.CreatePrincipal(username);
} else
throw new Exception( "Fail on validate user " + username );

May 20, 2008 12:01
Jun 02, 2008 18:10

Hi Ruwen,


Many thanks for your reply.  Unfortunately that code only seems to work in EPiServer 5.  I've worked around the problem for now by not requiring to change the user ID at all.


What originally motivated the problem was that I was getting AccessDenied errors when loading and saving some pages, and there is no "NoAccess" enum value in EPiServe, however using AccessControlList.NoAccess and passing that as the AccessLevel parameter allowed me to work around the problem.




Jun 02, 2008 20:09
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.