November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
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
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;
[...]
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()"
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?
Try to set System.Threading.Thread.CurrentPrincipal instead of CurrentUser.
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
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
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
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
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
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