16.01.2013 Views

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

936 Part IX: Maintaining a Server in Windows SharePoint Services<br />

<strong>Microsoft</strong>.SharePoint.WebControls Namespace<br />

The <strong>Microsoft</strong>.SharePoint.WebControls namespace contains <strong>Microsoft</strong> ASP.NET<br />

server controls that are used on site <strong>and</strong> list pages in a SharePoint site. This<br />

namespace can be found in the Windows SharePoint Services assembly (in<br />

<strong>Microsoft</strong>.SharePoint.dll). The major class, SPControl, provides methods for getting<br />

or setting the context of requests <strong>and</strong> serves as the base class from which other<br />

controls in this namespace derive.<br />

In general, although the set of Web controls within the <strong>Microsoft</strong>.SharePoint<br />

.WebControls namespace are used extensively in SharePoint <strong>Products</strong> <strong>and</strong> <strong>Technologies</strong>,<br />

they are of very limited usefulness to a third-party developer. In this section,<br />

the most interesting controls will be shown. If you want to find out more about the<br />

other controls, the best approach would be to see how the controls are used in the<br />

layouts .aspx files <strong>and</strong> experiment.<br />

The SPControl Class<br />

The SPControl class provides methods for getting or setting the context of the<br />

request <strong>and</strong> serves as the base server control from which other controls in the<br />

<strong>Microsoft</strong>.SharePoint.WebControls namespace derive. As such, SPControl is very<br />

important when programming the Windows SharePoint Services object model.<br />

The SPControl class can be used in a Web Part, in a custom Web service (in _vti<br />

_bin), or in an ASPX page or a Web Application (in _layouts). The following code<br />

uses the GetContextSite method to return the site collection that serves as the context<br />

for the current HTTP request. It also uses the GetContextWeb method to return the<br />

website that serves as the context for the current HTTP request. Finally, it shows<br />

how to retrieve the top-level website from the current site collection.<br />

SPSite siteCollection = SPControl.GetContextSite(Context);<br />

SPWeb site = SPControl.GetContextWeb(Context);<br />

SPWeb topLevelSite = SPControl.GetContextSite(Context).RootWeb;<br />

The FormDigest Control Class<br />

The FormDigest class inserts a security validation within the form of an .aspx<br />

page. To make posts from a Web application that modifies the contents of the<br />

database, you must include the FormDigest control in the form making the post.<br />

The FormDigest control generates a security validation, or message digest, to help<br />

prevent the type of attack whereby a user is tricked into posting data to the server<br />

without knowing it. The security validation is specific to a user, a site, <strong>and</strong> a time<br />

period, <strong>and</strong> it expires after a configurable amount of time. When the user requests<br />

a page, the server returns the page with security validation inserted. When the<br />

user then submits the form, the server verifies that the security validation has not<br />

changed. If you want to do website or lower-level operations in your page, you<br />

need to use the FormDigestol.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!