March 2007 Entries

How To Programmatically Disable Custom Errors and Enable Debugging And Stack Trace In WSS

Thursday, March 29, 2007

If you're doing SharePoint v3 development you probably already know that you should make a couple of changes to your web.config to make your time spent debugging a little more bearable.

Conveniently, there's also a new class this time around which allows you to make changes to web.config files across your farm using the WSS API.

Putting these two together, the code to make these changes would look something like this:

   1:  SPWebApplication webApp = siteCollection.WebApplication;
   2:  SPWebConfigModification callStackModification = new SPWebConfigModification("CallStack", "configuration/SharePoint/SafeMode");
   3:  callStackModification.Value = "true";
   4:  callStackModification.Owner = typeof(Program).FullName;
   5:  callStackModification.Sequence = 0;
   6:  callStackModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
   7:  SPWebConfigModification customErrorsModification = new SPWebConfigModification("mode", "configuration/system.web/customErrors");
   8:  customErrorsModification.Value = "Off";
   9:  customErrorsModification.Owner = typeof(Program).FullName;
  10:  customErrorsModification.Sequence = 1;
  11:  customErrorsModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
  12:  SPWebConfigModification debugModification = new SPWebConfigModification("debug", "configuration/system.web/compilation");
  13:  debugModification.Value = "true";
  14:  debugModification.Owner = typeof(Program).FullName;
  15:  debugModification.Sequence = 2;
  16:  debugModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
  17:  webApp.WebConfigModifications.Add(callStackModification);
  18:  webApp.WebConfigModifications.Add(customErrorsModification);
  19:  webApp.WebConfigModifications.Add(debugModification);
  20:  webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
  21:  webApp.Update();

I use this in a console application which I call from script when provisioning a farm on my development machine, you can download the source here.

You might also want to have a look at the web.config modification manager for SharePoint. It lets you manage changes made using SPWebConfigModification via the browser, and works really well for adding and removing individual changes. It would also be a good place to start from if you wanted to create a page to simultaneously flip all these debug settings without heading for the command line.

4 Comments | SharePoint

I Finally Went And Did It

Thursday, March 22, 2007

Without the Internet, without people doing this (and without the Global Index, obviously) I don't think I could do my job as a developer. In fact, I couldn't do my job as a developer. With this in mind, I've setup this blog so that maybe I can give something back and ease my conscience at the same time.

Since I spend a great deal of time working on or thinking about the SharePoint project I'm currently involved with, it's likely I'll post about that most frequently, at least for the time being. I also want to post on related computing, developer topics too, so we'll see how things work out.

Targeting this post at my current readership, here are a couple of thoughts I might need to remind myself of in the future.

  1. I chose to start this. If at anytime it becomes too much work, too stressful or too boring I'm allowed to stop.
  2. The signal-to-noise ratio of the Internet is low enough already. I should avoid making things worse for everybody's sake.

I finally went and did it.

3 Comments | Musings