Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

PublishingWeb.GetPublishingWeb can't be called as anonymous user?

  Asked By: Pankaj    Date: Jan 04    Category: Sharepoint    Views: 1932

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?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Jacklyn Burnett     Answered On: Jan 04

If you get 401 while running  the code  you mentioned, you need to run  it impersonated. You can do it for example by using SPSecurity.RunWithElevatedPrivileges (more details @ blogs.devhorizon.com/.../484.aspx)