Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Allow AnonymousAcces

  Asked By: Ramsey    Date: May 08    Category: Sharepoint    Views: 1880

I am working on the internet sites on sharepoint and was hosted , but one
thing we have done lost of coding (customisation ) through VS2005 as per the
client reqirement . i had struck with one thing that is AllowAnonymous Acces
for the web in the site permissions . How can set the AllowAnonymous to be true
by using Objectmodel . as i seen it it is redirected to setanon.aspx page . but
i dont want any redirection to the page . as i m creating the Spwebs using
VS2005 while creating the SPweb i want the Allowanonymous acces to be true .

Please tell me if there any answer

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Trevor Davis     Answered On: May 08

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

 
Didn't find what you were looking for? Find more on Allow AnonymousAcces Or get search suggestion and latest updates.




Tagged: