Try our conversational search powered by Generative AI!

Problem With episerver Scheduler while running automatically.



I am using episerver Scheduled job when ever it runs automatically it throws exception "Object Refrence not set to an instance of an object". in my program i am using "(WindowsIdentity)HttpContext.Current.User.Identity;" any idea how to resolve this issue.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.UseDefaultCredentials = true;

to get an episerver page . please reply


Jan 23, 2012 14:45

You cannot use HttpContext.Current when it runs automatically, cause you don't have one. You have to use another approach. A setting or something to choose which account to impersonate.

Jan 23, 2012 14:54

You can programmatically set the user by calling:

PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("userName");


Jan 23, 2012 15:28
Hi Johan
PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("userName");
How to set it??? I mean if the username willbe of the system where we are running the application????? or we can add Active directory User????


Jan 23, 2012 15:39

In that case you can configure the schedular service to run under another account instead. See

Jan 23, 2012 15:44


Can we set a set a user identity and then impersonate it??????if yes please help how it can be done????

Jan 23, 2012 16:12
* 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.