Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

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

  Asked By: Pankaj Das         Date: Jan 04, 2010      Category: Sharepoint      Views: 403
 

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?

Tagged:                

 

1 Answer Found

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

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)

 


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].