Title: ASP'NET v 1'1 Web Parts Programming for SPS 2003
1ASP.NET v 1.1 Web Parts Programming for SPS 2003
- Hammad Rajjoub INETA Speakers Bureau.
2public override string ToString()
- Technical Lead, Applied Business Applications,
Dubai, UAE - INETA UG Leader
- INETA Member Of Speakers Bureau
- IDotNetEvangelist
3Agenda
- Background Basics
- Infrastructure Life Cycle
- Debugging
- Advanced Topics
- Distribution and Deployment
- Best Practices
- Road Ahead
4Background
- "The New World of Work"
- Remember Dashboards ?
- Portals
- Design time vs. Run Time
- Collaborative Applications?
5Web Part Basics - Review
- Core part of Windows Sharepoint Portal Server
Product and Technologies - ASP.NET server controls
- (Dynamic) Web Parts are added to Web Part Zones
at run time - Blur traditional boundary between design time and
run time
6Web Part Basics - Review (contd.)
- Allows developers to develop collaborative
applications using WSS (Windows Sharepoint
Services) - Extensible (System.Web.UI.Control)
- Allows developers to develop and End-Users to
customize - One of the reasons you would choose Sharepoint
Portal Server
7Web Part Basics - Review (contd.)
- Advantages for .Net Developers
- ASP.NET Programming Model
- Full use of ASP.NET Server Controls
- Built on top of .NET Framework
- Visual Studio.NET
- Build components that can be used by others
8Web Part Infrastructure
ASP.NET Page
ASP.NET Page
Web Parts Framework
Zone 1
Zone 2
Zone 3
Source MSDN
9Life Cycle
10Life Cycle
WebPart.OnInit()
System.Web.UI.LoadViewState()
Event Handlers for Controls Addedc
WebPart.OnPreRender()
System.Web.UI.SaveViewState()
WebPart.RenderWebPart( System.Web.UI.HtmlTextWrite
r)
System.Web.UI.Control.Dispose()
System.Web.UI.Control.UnLoad()
11Developing Web Parts with VS.NET
- Using Web Part Templates in Visual Studio.NET
- Understanding files in the Visual Studio
Solution - DWP File
- Web Part Definition File. This is an XML File
that contains title, description, assembly and
type name of the web part - CS File
- Web Part Class file that contains a class that
inherits from Microsoft.SharePoint.WebPartPages.We
bPart - Manifest.XML
- An XML file that dictates how the web part should
be installed by an installer
12Developing Web Parts with VS.NET (contd.)
- Modify CS File
- Override CreateChildControls
- Override RenderWebPart
- Implement appropriate event handlers
- Modify dwp and manifest.xml files
13Developing Web Parts with VS.NET 2003
14Debugging Web Parts
- Hard to debug web parts that are deployed in GAC
(Global Assembly Cache) - Place pdb file along with .dll in bin directory,
so that IIS W3P.exe can access it - Attaching w3p.exe process to visual studio.Net
debugger
15Debugging Web Parts (contd.)
- Configuring web.config file to enable debugging.
- Trust Level
- lttrust level"WSS_Medium" originUrl"" /gt
- Custom Errors switched Off
- ltcustomErrors mode"Off" /gt
- Debugging enabled.
- ltSafeMode MaxControls"50" CallStacktrue" /gt
16Debugging Web Parts
17Web Parts Development Advanced Topics
- Security
- Rendering Techniques
- Connectable Web Parts
18Advanced Topics Security
- To cater security needs of Web Parts deployment
and operation we need to understand thoroughly
following things - Strong Naming
- Strong Name ensures that your web part is
globally unique and hence can not be confused
with any other web part. Which creates a level of
trust! - Strong Name also ensures version lineage of the
web part. It ensures that every sub sequent
version of the web part came from the source
(developer or ISV). More trust! - Strongly named web part can only reference
strongly named assemblies - As for the development environment you can skip
strong name verification by setting
AssemblyDelaySign to true
19Advanced Topics Security (contd.)
- Code Access Security
- Restricted access to critical resources
- CAS (Code Access Security) configuration required
- CAS is configured by means of series of
configuration files - Machine.config ltsecurityPolicygt and lttrustLevelgt
tags - Web.Config available in \Inetpub\wwwRoot\.
Defines two additional lttrustLevelgt tags known as
WSS_Minimal and WSS_Medium - By default each web site has a trust level of
WSS_Minimal - With WSS_Minimal, web parts can not access
databases, manipulate IO and access Sharepoint
Object Model
20Advanced Topics Security (contd.)
- Customizing Policy Files
- As a web part developer you have three options
for raising security of a web part. - Option 1
- Modify web.config to raise the trust level of
all Sharepoint Services. - lttrust level WSS_Medium original/gt
- Option 2
- Deploy all your web parts into the Global
Assembly Cache (GAC). - Option 3
- Creating your own custom policy file.
- You will need to re-start the IIS.
- The most tedious of all the three approaches
but its the recommended approach for production
env.
21Advanced Topics Security (contd.)
- Marking Web Part As SafeControl
- After the CAS for web part has been configured
web part needs to be marked as Safe - ltSafeControlsgt tag of Web.Config file
- contains information about controls that have
been marked as safe - ltSafeContorl AssemblyFully Qualified Name for
Assembly NamespaceNameSpace TypeName/gt
22Advanced Topics Rendering Techniques
- Rendering techniques for Web Parts
- HTMLTextWriter Doing it the usual way
- ASP.Net User Controls We love Drag Drop
- SmartParts Simple like any thing!
23Advanced Topics Rendering Techniques (contd.)
- RenderWebPart with HTMLText Writer
- No Drag Drop!
- Create and add asp.net contol to the control
collection (CreateChildControls()) - Generate HTML for your web part, very much the
way ASP.NET Server Controls render HTML content
to the client - Write your HTML using HTMLTextWriter in
RenderWebPartMethod - Generate usual TDs and TRs using either
WriteBeginTag/WriteEndTag or Write methods on
HTML Text Writer Object - Tedious and can slow down over all development,
but once used to it shouldnt be a problem
24Advanced Topics Rendering Techniques (contd.)
- Using ASP.NET Controls
- Drag and Drop!
- Use ASP.NET server controls, custom controls and
user controls at your own discretion - Increased productivity
- Make sure that you have placed your ASP.NET
controls in an excluded (from STSFLTR.dll)
directory - Call LoadControl method on Page object in
CreateChildControls method of your Web Part - Call RenderControl() method on your custom
control to render output in RenderWebPart - Think about developing a generic HostWebPart for
your custom/asp.net server controls
25Advanced Topics Rendering Techniques (contd.)
- Using SmartParts
- A SharePoint Webpart that can host any ASP.NET
user control. Create your webparts by using the
VS.NET designer instead of coding everything by
hand!
26Distributing Deploying Web Parts
- Manual Copy
- CAB File Deployment
- MSI Installations
27Distributing Deploying Web Parts (contd.)
- Manual Install
- Copy assembly file in either
- GAC
- Copy resources to \Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\wpresources - Bin Directory of Virtual Server
- Copy resources to \inetpub\wwwroot\wpresources
- Copy Web Part Definitions File (DWP) to
\inetpub\wwwroot\wpcatalog folder - Adjust configuration (for ltSafeControlgt and CAS)
28Distributing Deploying Web Parts (contd.)
- CAB File Deployment
- Web Part Package file contains
- Assembly File (.dll)
- Web Part Definition File (.dwp)
- Manifest.xml
- Resource File(s)
- Use ststadm.exe
- Stsadm.exe o addwppackage filename
ltyourCabFileNameHeregt -GlobalInstall Force - Ensure CAS
29Distributing Deploying Web Parts (contd.)
- MSI File Installer
- WPPackager makes an msi file for you web part to
be deployed - Provides all the functionality of CAB file
installation plus CAS support and availability in
control panel
30Best Practices
- Handle All Exceptions to prevent all exceptions
- Check Permissions before rendering your web part
and render output accordingly - Validate properties before saving them into
database - Validate all user inputs
- Register the client side script shared by
multiple web parts to improve performance - Specify whether web parts can be exported
31Best Practices (contd.)
- Implement IDesignTimeHtmlProvider interface in
your web part to ensure correct rendering - Make properties user friendly in tool pane
- HTMLEncode all the user input rendered to the
client - Use Simple Types for the custom properties you
define - To improve Web Parts performance use
- Asynchronous Data Fetch
- Caching
32Summary
- Brief Introduction
- Development and Debugging
- Advanced Features
- Best Practices
- Distribution and Deployment
33Road Ahead
- ASP.NET 2.0 Rocks!
- WSS 3.0 Release
- Backward compatibility!
- Keep Rocking!
34Links and Resources
- Microsoft Sharepoint Building Office 2003
Solutions ( APress) - Advance Sharepoint Services Solutions
- Links
- http//msdn.microsoft.com/sharepoint
- http//www.gotdotnet.com/team/sharepoint/
- http//www.sharepointcustomization.com/default.asp
x - And my blog, of course http//dotnetwizards.blogs
pot.com
35Q/A and Feedback forms.
- Ask your questions
- Comments and Feed back
- Mail hammad.rajjoub_at_ineta.org
- URLhttp//dotnetwizards.blogspot.com