Try our conversational search powered by Generative AI!

Run a scheduled job as a specific user in 4.62B


I've read about how to run a scheduled job as a specific user in CMS 5 (, and need to know how to do this in 4.62B (.NET 2.0).

How is this done?


Dec 03, 2008 10:47

Look at this FAQ. 

The logic you need is there (you just need to reverse it).


Edited, Dec 03, 2008 12:47

Thanks for your reply!

Unfortunately I get the following compilation error:

Keyword 'this' is not valid in a static property, static method, or static field initializer

An object reference is required for the nonstatic field, method, or property 'EPiServer.PageBase.CurrentUser.get'


Code Example:

public class ExportOrders : TemplatePage

public static string Execute()

System.Security.Principal.IPrincipal principal = AuthenticationProvider.Authenticate(this, "username", "password");

CurrentUser = principal as UnifiedPrincipal;



Dec 04, 2008 9:08

From the Stacktrace (NullException on Order.Load):

 " at EPiStore.AttributeFactory.ᐁ()\r\n at EPiStore.AttributeFactory.GetAttributeSettings(PageData itemPage)\r\n at EPiStore.DataAbstraction.CartItem..ctor(Int32 pageID, Int32 quantity, Double price)\r\n at EPiStore.DataAbstraction.CartItem..ctor(Int32 pageID)\r\n at EPiStore.DataAbstraction.OrderItem..ctor(Int32 pageID)\r\n at EPiStore.DataAbstraction.Order.ᐁ(DataSet )\r\n at EPiStore.DataAbstraction.Order.ᐁ(DataSet )\r\n at EPiStore.DataAbstraction.Order.Load(Int32 id)\r\n at KnowIT.Shop.Core.ExportOrders.Execute()"


Dec 08, 2008 10:19
You are calling Authenticate() from a static method, therefor you can not use "this" as a parameter. Try to use something else, eg "new ExportOrders()".
Dec 08, 2008 11:39

Thanks for the suggestion.

Even if I make that change, I still get en error message for CurrentPage (for the same reason, since I'm using a static method):

An object reference is required for the nonstatic field, method, or property 'EPiServer.PageBase.CurrentUser.get'  

Is it possible to create an instance of the ExportOrders class (from inside the static method Execute()), and run the Scheduled Job through that?



Dec 08, 2008 14:41

Try to set System.Threading.Thread.CurrentPrincipal instead of CurrentUser.

Dec 09, 2008 9:35

Thanks, Erik, but I still get the same error message, and the EPiServer Support seems to have given up on this issue.

More ideas are greatly appreciated! :)



Dec 15, 2008 11:17

Where do you use CurrentPage here? You cannot use CurrentPage in a scheduled task. There is no request, no HttpContext, no template and no current page :-)


Dec 15, 2008 11:55

Hi Steve!

I'm not using CurrentPage, I'm using the method Load in the class Order (EPiStore), which deep down is fetching properties from the product (which is a Page), and there is my problem.

Since there is no overloaded version of Order.Load, I can't edit the accesslevel.


Best Regards


Dec 15, 2008 13:36

Ah, hm, bummer.

And you have tried setting Thread.CurrentPrincipal to a known Principal with the needed access rights? Cause that is the one used to check for access rights.

You should be able to create a UnifiedPrincipal with an UserSid object (UserSid.Load(...)).


Dec 15, 2008 15:06

Steve has the working solution for EPiServer 4, along with earlier mentioned, this works:

System.Security.Principal.IPrincipal principal = AuthenticationProvider.Authenticate(new YourClassThatYouAreInNow(), "user", "password");
Thread.CurrentPrincipal = principal as UnifiedPrincipal;
/ Jacob
Edited, Oct 26, 2010 10:31
* 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.