Recently I was having trouble with the following code:
SPWebApplication webApp = site.WebApplication;
webApp.FormDigestSettings.Enabled = true;
site.WorkflowManager.StartWorkflow(GetListItem(web, docList.ContainingDocumentLibrary, docFile.UniqueId), foundWorkflow, foundWorkflow.AssociationData, true);
//Turn security validation back on.
webApp.FormDigestSettings.Enabled = false;
More to the point, I got the following exception on the line webApp.FormDigestSettings.Enabled = true;
[5/18/2009--4:05 PM] Exception caught: Access denied.
[5/18/2009--4:05 PM] Stack: at Microsoft.SharePoint.Administration.SPFormDigestSettings.set_Enabled(Boolean value)
at GlobalDocumentCenter.GDC_Document.<>c__DisplayClass1.<ctrSubmitBtn_Click>b__0()
This code previously worked on this box about 2 months ago.
I first sent out an email to some buddies looking for help.
I did some searches and verified a few tidbits:
1. The app pool identity is in the Farm Admins.
2. The app pool identity is in the admin group on the box.
A friend of mine, as well, a fellow blogger (see side bar for Jason's blog) suggested "Restart the App Pool". We ignored him. He is a bit of a clown around the office, and is only a graphic artist.
However, a little bit after his email, and not getting anywhere, I asked for the app pool to be restarted. Low and behold, my problem went away.
The moral of the story... While most programmers want to think we live in a perfect world where frameworks and operating system code doesn't become corrupt somehow, it does. Always remember the simple stuff, often times it works. Restart the app pool. Restart the box. The scary part is more times than it should, it fixes the problem. As well, I would rather spend 5 minutes restarting and find out that didn't fix the problem, rather than spend hours and days or weeks on something that we just can't fix, and finally we realize a five minute restart would have fixed the issue.
May the schwartz be with you.