Try our conversational search powered by Generative AI!

Problem With episerver Scheduler while running automatically.

Vote:
 

Hi,

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

 

#56485
Jan 23, 2012 14:45
Vote:
 

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.

#56486
Jan 23, 2012 14:54
Vote:
 

You can programmatically set the user by calling:

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

    

#56488
Jan 23, 2012 15:28
Vote:
 
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????

    

#56489
Jan 23, 2012 15:39
Vote:
 

In that case you can configure the schedular service to run under another account instead. See http://www.windowsecurity.com/articles/controlling-windows-services-service-accounts.html.

#56490
Jan 23, 2012 15:44
Vote:
 

Hello

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

#56491
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.