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 (http://labs.episerver.com/en/Blogs/Ted-Nyberg/Dates/112276/8/Run-a-scheduled-job-as-a-specific-EPiServer-user/), and need to know how to do this in 4.62B (.NET 2.0).

How is this done?

Jakob

#26381 Dec 03, 2008 10:47
  • Member since: 2001
     

    Look at this FAQ.

    http://world.episerver.com/en/FAQ/Items/How-do-I-save-a-page-as-an-anonymous-user/ 

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

    /Steve

    #26387 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;

     

    [...]

    #26398 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()"

     

    #26479 Dec 08, 2008 10:19
  • Member since: 2004
     
    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()".
    #26481 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?

     

     

    #26483 Dec 08, 2008 14:41
  • Member since: 2004
     

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

    #26514 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! :)

     

    Jakob

    #26637 Dec 15, 2008 11:17
  • Member since: 2001
     

    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 :-)

    /steve

    #26641 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

    Jakob

    #26647 Dec 15, 2008 13:36
  • Member since: 2001
     

    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(...)).

    /steve

    #26655 Dec 15, 2008 15:06
First   1 2   Last