Allow anonymous access to custom application pages


Hi everyone,

Today I’ll talk about a problem I encountered some time ago. The project had some applicative pages which needed to be deployed on a site where anonymous access is enabled.

Those pages had to be used both by registered users and anonymous users. All the code of the page had been properly implemented (with some runwithelevatedprivilege), however when accessing the page, anonymous users faced an awful  “access denied“.

After some investigation, it turns out that the application pages generated by VisualStudio inherited LayoutsPageBase class. Looking a little in the msdn documentation, we came across this class definition:

« Represents an application page to which access can be limited to users that possess certain rights. ».

So that’s the problem!

After a little research we came across the UnsecuredLayoutsPageBase class and it’s definition.

« Represents the base class for application pages that explicitly do not require the user to have any permissions, such as the access denied page.».

And then, we just changed the base class from LayoutsPageBase to UnsecuredLayoutsPageBase to fix this permission problem!

UPDATE :

I used to apply this code on SharePoint 2007 but recently when I tested on a 2010, it didn’t worked well.

To have your page working on anonymous on 2010 , you must also override the “AllowAnonymousAccess” function like this

 protected override bool AllowAnonymousAccess { get { return true; } } 

Christopher.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s