Whilst working with a client to customise some of their public facing Sharepoint pages I developed a number of custom web parts. One of these web sites was getting some of its information by enumerating the different sub sites of the site collection. Unfortunately while this worked well when the site’s users were authenticated it didn’t work if they were anonymous users, which of course the majority of the sites users would be. When an anonymous users navigated to a page with this webpart they were prompted for their credentials.
There is a simple solution to this problem which is to us the SPSecurity.RunWithElevatedPrivileges method, passing in a delegate to the work that is requiring authentication. Your code would look something like this: