Facts about Web Part / Sharepoint Pages

Sahil Malik: The word visual simply refers to the fact that you get visual editing experience when developing this WebPart in Visual Studio. This is possible because a Visual WebPart is based on an ASCX, also known as a user control. This WebPart being an ASCX also presents a significant limitation. The deployment of this WebPart requires an ASCX file to be copied on the file system. Since the deployment requires you to make changes to the file system, a Visual WebPart always has to be deployed as a farm solution.

(“Visual Web Part” à User Control; “Web Part” à Server Control)

So Web Part Programming à Farm Solution.

Two kinds of Sharepoint pages:

  1. Application pages: stored on disks
    in a standard SharePoint folder called the layouts folder;
    runs in ASP.NET trust level of unrestricted
    great for administrative-like functions
  2. Site pages: stored in content database
    greate for presenting contents and functionality to the end user;
    easily adapt the look/feel using default.master
    web Part Pages are normally Site Pages with webpart zones in it. (webpart manager lives in master page)

In VS 2010, to develop an application page to be migrated to Sharepoint server, create an empty Sharepoint project, farm solution, name it “SomePages”. Add a Sharepoint “Layouts” mapped Folder and place the file in it. After that, the Layout folder will be added to the solution, under which there is a sub-folder which is your VS 2010 solution name. This is good because many solutions can co-exists under the Layout folder.

Right click the “Layout” folder, add a new item (application page) called MyApplicationPage.aspx.

To add this application page to the menu, create this XML file (elements.xml) in a module and deploy it as part of the feature:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=”http://schemas.microsoft.com/SharePoint/”&gt;
<CustomAction Id=”MyApplicationPage”
GroupId=”SiteActions” Location=”Microsoft.SharePoint.StandardMenu”
Sequence=”2001″ ImageUrl=”_layouts/images/somepages/wslogo.gif”
Title=”My ApplicationPage” Description=”This page will tell you what
security level it is operating under.”>
<UrlAction Url=”~site/_layouts/SomePages/MyApplicationPage.aspx”/>
</CustomAction>
</Elements>

So then you would get this:

If you create an application in site-collection, the same page will be available in each sub-site, e.g.,
http://sp2010/subsite_A/_layouts/SomePages/MyApplicationPage.aspx.
http://sp2010/subsite_B/_layouts/SomePages/MyApplicationPage.aspx.

Whenever SharePoint gets an HTTP request, it uses an ASP.NET concept called as the VirtualPathProvider to fetch the actual contents of the page.
———————————————————————————————

To secure an application page (since it’s unrestricted):

1. Require the user to be a site collection admin (explained below) or
2. Specify an explocit permissions string necessary to access the page.

Check whether a site collection admin: Add this code to MyApplicationPage.aspx:

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

and add
RequireSiteAdministrator=”true”
to the CustomAction element in the elements.xml.
———————————————————————————————–

Summary of differences between Application page and Site Page:
1. An application page is deployed to the file system and a SitePage is deployed to the content database.
2. An application page requires a farm solution and a SitePage can be deployed using a sandbox solution
3. An application page is shared all across the web front end, but a SitePage is unique to its location.
4. A SitePage can be easily customized through SharePoint Designer, but an application page usually requires Visual Studio.
5. Custom application pages should be secured and PageParserPaths for site pages should be avoided.
6. Feature Receivers are necessary to clean up after a site page feature is deactivated. Application page artifacts are removed from the file system when the solution is retracted.

Advertisements
Post a comment or leave a trackback: Trackback URL.

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

%d bloggers like this: