Here is the code
// For Enabling Anonymous Access at Webapplication level that you
configure from CA
SPWebApplication webApp = SPWebApplication.Lookup(new
Uri("http://sharepoint2007"));
SPIisSettings iis =
Microsoft.SharePoint.Administration.SPIisSettings.CreateFromExistingWebSite(webA\
pp.DisplayName);
iis.AllowAnonymous = true;
Assembly asm = Assembly.Load(@"Microsoft.SharePoint,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
Type t =
asm.GetType("Microsoft.SharePoint.Administration.SPWebApplication");
MethodInfo mi = t.GetMethod("UpdateAuthenticationSettings",
BindingFlags.Instance | BindingFlags.NonPublic,
null, new Type[] { typeof(SPUrlZone), typeof(SPIisSettings)
}, null);
mi.Invoke(webApp, new object[] { SPUrlZone.Default, iis });
// for enabling site level anonymous access that we enable from
setanon.aspx
SPSite sc = new SPSite("http://sharepoint2007");
SPWeb site = sc.RootWeb;
site.AnonymousState = SPWeb.WebAnonymousState.On;
site.Update();
sc.Dispose();
site.Dispose();
It was good expericene working on your problem
Tip: To find the class and methods you need to work on is to open the Sharepoint
Application pages like setanon.aspx,
then get the assembly name where code-behind sitting. Then you can open that
assembly in any disassembler
that gives you hint that how sharepoint itself is performing that operation