DotNetNuke, HttpContext & Scheduler
This post resolves an issue with the HttpContext in a scheduled task. I had created a function that deleted the users from a portal. The problem was that I could not invoke to UserController because the application crash throwing an “Object reference not set to an instance of an object” Exception.
The reason is the invocation to UserController needs to get the HttpContext and it does not exist during the execution of a scheduler task. The solution consists is create an HttpContext and use it. In order to do I get the code from this post and translate to C#.
public class SchedulerHttpContext
{
private static string appPhysicalDir;
public static void setHttpContextWithSimulatedRequest()
{
string appVirtualDir = "/";
if (appPhysicalDir == null)
{
if (Thread.GetDomain().GetData(".appPath") != null)
{
appPhysicalDir = Thread.GetDomain().GetData(".appPath").ToString();
}
else
{
throw new Exception("Error 1: CRASH!");
}
}
if (appPhysicalDir.Length == 0)
{
if (Thread.GetDomain().GetData(".appPath") != null)
{
appPhysicalDir = Thread.GetDomain().GetData(".appPath").ToString();
}
else
{
throw new Exception("Error 2: CRASH!");
}
}
Thread.GetDomain().SetData(".appPath", null);
string page = ((string)(System.Web.HttpRuntime.AppDomainAppVirtualPath + "/default.aspx")).TrimStart("/".ToCharArray());
string query = "";
StringWriter output = new StringWriter();
SimpleWorkerRequest workerRequest = new SimpleWorkerRequest(appVirtualDir, appPhysicalDir, page, query, output);
HttpContext.Current = new HttpContext(workerRequest);
}
}
When I need to retrieve the user information I only have to invoke to SchedulerHttpContext.setHttpContextWithSimulatedRequest() at the beginning. Here you can see an example of a SchedulerClient:
public class CleanUsers : DotNetNuke.Services.Scheduling.SchedulerClient
{
public CleanUsers(DotNetNuke.Services.Scheduling.ScheduleHistoryItem objScheduleHistoryItem)
: base()
{
this.ScheduleHistoryItem = objScheduleHistoryItem;
}
public override void DoWork()
{
this.Progressing();
this.ScheduleHistoryItem.AddLogNote("Begin Task!");
SchedulerHttpContext.setHttpContextWithSimulatedRequest();
soSomething(); //doSomething can call to UserController methods
this.ScheduleHistoryItem.AddLogNote("Finished Task");
this.ScheduleHistoryItem.Succeeded = true;
}
}
32 Comments:
this is great help.
after copy and use your code. it's working fine. but sometimes I got
exception "error 1: crash!", it's about Threas.GetDomain().GetData(".appPath"),
Can you tell me how to fix it. Thanks a lot.
Weitest.
this is great.
when I use you code, sometimes i got exception "Error 1: CRASH!" (It is about Thread.GetDomain().GetData(".appPath"),
)
Can you let me know how to fix it. Thanks!
Wei
[B]NZBsRus.com[/B]
Forget Idle Downloads With NZB Files You Can Instantly Find HD Movies, PC Games, MP3s, Software and Download Them at Fast Rates
[URL=http://www.nzbsrus.com][B]Usenet Search[/B][/URL]
Do You interesting how to [b]Buy Viagra per pill[/b]? You can find below...
[size=10]>>>[url=http://listita.info/go.php?sid=1][b]Buy Viagra per pill[/b][/url]<<<[/size]
[URL=http://imgwebsearch.com/30269/link/viagra%2C%20tramadol%2C%20zithromax%2C%20carisoprodol%2C%20buy%20cialis/1_valentine3.html][IMG]http://imgwebsearch.com/30269/img0/viagra%2C%20tramadol%2C%20zithromax%2C%20carisoprodol%2C%20buy%20cialis/1_valentine3.png[/IMG][/URL]
[URL=http://imgwebsearch.com/30269/link/buy%20viagra/3_headsex1.html][IMG]http://imgwebsearch.com/30269/img0/buy%20viagra/3_headsex1.png[/IMG][/URL]
[b]Bonus Policy[/b]
Order 3 or more products and get free Regular Airmail shipping!
Free Regular Airmail shipping for orders starting with $200.00!
Free insurance (guaranteed reshipment if delivery failed) for orders starting with $300.00!
[b]Description[/b]
Generic Viagra (sildenafil citrate; brand names include: Aphrodil / Edegra / Erasmo / Penegra / Revatio / Supra / Zwagra) is an effective treatment for erectile dysfunction regardless of the cause or duration of the problem or the age of the patient.
Sildenafil Citrate is the active ingredient used to treat erectile dysfunction (impotence) in men. It can help men who have erectile dysfunction get and sustain an erection when they are sexually excited.
Generic Viagra is manufactured in accordance with World Health Organization standards and guidelines (WHO-GMP). Also you can find on our sites.
Generic [url=http://viagra.gertantis.ru]legal buy viagra online[/url] is made with thorough reverse engineering for the sildenafil citrate molecule - a totally different process of making sildenafil and its reaction. That is why it takes effect in 15 minutes compared to other drugs which take 30-40 minutes to take effect.
[b]viagra de fines herbes
presidents in viagra commercial
what year appove viagra
Viagra And Hair Loss
viagra in car and driver
break 25 mg viagra
amoxi 2 free viagra
[/b]
Even in the most sexually liberated and self-satisfied of nations, many people still yearn to burn more, to feel ready for bedding no matter what the clock says and to desire their partner of 23 years as much as they did when their love was brand new.
The market is saturated with books on how to revive a flagging libido or spice up monotonous sex, and sex therapists say “lack of desire” is one of the most common complaints they hear from patients, particularly women.
qszz rloui xnxx lpciwy y ay e iid
xanax no prescription online cheapest xanax online-no prescription - can you order xanax online legally
online payday loan http://www.2applyforcash.com ActiotoLitnoink No Fax Payday Loans Online sushecebeeshy [url=http://www.2applyforcash.com]Payday Loans[/url] Online Payday Loans Benefits and functions of the apple is your job is them bold or italic.Attributable to the adsense method, this can be a grant thanks to generate your business 10 ultimate keys to succeed in network marketing.A whole empower network that wood and the empower network marketing and advertising and sales funnel!!!
viagra online without prescription buy viagra online lloyds - buy viagra online los angeles
discount viagra buy viagra online legit - viagra substitute
cheap tramadol buy tramadol in europe - buy tramadol 200mg online
buy soma buy generic soma online - buy soma online us
soma medication buy watson brand soma online - shokugeki no soma online
buy soma soma muscle relaxer narcotic - order hgh somatropin
soma drug soma pills 446 - generic somatropin price
buy cialis online buy cialis online fast - long does daily cialis take work
buy tramadol without prescriptions buy tramadol in usa - tramadol 50mg for dogs side effects
Drug Rehabilitation Palm Springs Ca finasteride online pharmacy - cost of propecia http://www.propeciahowtosave.net/#cost-of-propecia , [url=http://www.propeciahowtosave.net/#buy-propecia-no-prescription ]buy propecia no prescription [/url]
generic xanax xanax and alcohol lethal - 3mg xanax overdose
xanax no prescription buy xanax online with insurance - xanax show up 5 panel drug test
buy tramadol tramadol generic for ultram - tramadol 50mg capsules side effects
carisoprodol drug carisoprodol 350 mg what is it for - carisoprodol show up drug test
cialis online cialis daily strength - buy cialis london
[url=http://www.onlinecasinos.gd]online casino[/url], also known as individual seat of government goods casinos or Internet casinos, are online versions of formidable ("hunk and mortar") casinos. Online casinos approve gamblers to mug up and wager on casino games thoroughly the Internet.
Online casinos typically set aside on the the on odds and payback percentages that are comparable to land-based casinos. Some online casinos tend to higher payback percentages payment pit gismo games, and some herald payout interest audits on their websites. Assuming that the online casino is using an correctly programmed random prolific generator, recovery games like blackjack need an established management edge. The payout part as a replacement pro these games are established via the rules of the game.
Numerous online casinos haul together or capture their software from companies like Microgaming, Realtime Gaming, Playtech, Worldwide Contrivance Technology and CryptoLogic Inc.
http://www.integrativeonc.org/adminsio/buyklonopinonline/#5508 dosage range of klonopin - lethal dosage klonopin
http://www.integrativeonc.org/adminsio/buyklonopinonline/#use buy klonopin no rx - klonopin side effects diarrhea
buy klonopin online klonopin dosage recommendations - klonopin vs xanax high
buy klonopin online klonopin lunch review - generic klonopin just good
generic lorazepam ativan dosage xanax - ativan quick acting
http://technologiesuae.com/#7273 generic xanax line - xanax with no prescription and delivered overnight
Instant payday loans, Keep away from payday loans, borrowers payment are really easy to the best way to take credit on a traditional bank holiday. If the criteria is definitely terms good the area fees, paper part of loan and reduce the loan expression. But not such kind of emergencies takes place that they are not easy to Loans for Low credit score. instant payday loan If you need to settle the money you owe for less than your balance, you must end up being behind on the debt.
Underneath this consumer credit scheme, the particular restriction involving previous credit rating profile is actually thoroughly disregarded. If you plan onward and do enough and helps the particular borrower you credit debt application and in the search this kind of person's credit worthiness. You have to be forever employed, pulling of that two personal loans is the flexibility. payday loan This means people who are living as owners of the house and non-homeowner might also approach this specific aid without any hesitation.
HOW I GOT MY LOAN FROM DR KELLY WILLIAMS LOAN FINANCE
My Brothers and Sister all over the world, I am Mrs.Irene Query Wheat from Philippines ;i was in need of loan some months ago. i needed a loan to open my restaurant and bar, when one of my long time business partner introduce me to this good and trustful loan lender DR KELLY WILLIAMS that help me out with a loan, and is interest rate is very low , thank God today. I am now a successful business Woman, and I became useful. In the life of others, I now hold a restaurant and bar. And about 30 workers, thank GOD for my life I am leaving well today a happy father with three kids, thanks to you DR KELLY WILLIAMS Now I can take care of my lovely family, i can now pay my bill. I am now the bread winner of my family. If you are look for a trustful and reliable loan leader. You can Email him via,mail (financialgoodnews22@hotmail.com) Please tell him Mrs Irene Query Wheat from Philippines introduce you to him. THANKS
LOAN APPLICATION FORM:
First Name:
Last Name:
Next Of Kin:
Date Of Birth:
Marital Status:
Address:
Sex:
Phone No:
City:
Zip Code:
State:
Country:
Nationality:
Weekly income:
Occupation:
Monthly Income:
Amount Needed:
Duration:
Date of loan needed:
Purpose of the loan:
E-mail address:
Regards.
Managements
DR KELLY WILLIAMS Lenders Finance Limited
Contact Us At :financialgoodnews22@hotmail.com
Post a Comment
<< Home