I have run into a strange issue that I hope someone can help me with.
I've added a codebehind file to one of my master pages to modify the behaviour of the sitemap. The code is compiled, signed with a strong name and added to the GAC through a solution package.
In the masterpage codebehind I run the following to get the url to the current web's start page:
PublishingWeb pweb = PublishingWeb.GetPublishingWeb(SPContext.Current.Web);
startPageUrl = pweb.DefaultPage.ServerRelativeUrl;
However, when running this code, I always get a 401 when I go as an anonymous user to the web, even though anonymous access is turned on. When I remove the code, everything works fine. There is not stacktracke with any exception, it just requests authentication from the user.
I even tried to set the trust mode to full and it didn't make any difference.
How can this code cause this behaviour? I would need to run this code to get the URL to the start page when visiting the site as an anonymous user.
Any thoughts or ideas?