Friday, June 19, 2009

Developing a Custom Control for Silverlight 2.0

  • Custom controls is used to extend the functionality of existing controls and even create new controls with new functionalities.
  • Creating custom controls is a great way to make Silverlight application more rich and unique
  • Once a custom control is built we can reuse it anywhere in other applications too.
  • Create a Silverlight Class Library Project in Visual Studio 2008.
  • Because this will be a Control Library we've to add a reference to System.Windows.Controls assembly. This assembly will have 1.0.0.0 as version number for Silverlight 2.0 Beta1
  • The next step we will add XmlnsDefinitionAttribute to our control Assembly
  • Select the generic.xaml in the Solution Explorer and set the properties to get this file embedded in a format we need
  • You've to delete the value of the Custom Tool property and set Build Action to "Resource".
  • Write the coding in the Xaml file and the design the media button.
  • To test this control we have to create a Silverlight Application Project. In Solution Explorer, right click the Solution's node and add a new Project to the Solution of type Silverlight Application.
  • For Silverlight Application Visual Studio asks us about the testing method we like to use for this Silverlight Application. For now, a test HTML page will be fine for us.
  • To use the control in our Test Application we've to add a reference to the Control Library Project.
  • Open the page.xaml and write the caoe for calling the media button and run the application.
  • Then a .dll file will be created. This file can be used to call the media button in other applications.


How to Store and Retrieve Application Settings Using Isolated Storage

•You store application settings using isolated storage by using members of the IsolatedStorageSettings class.
•This class implements a dictionary that is designed to store name/value pairs.
•Like all data stored in isolated storage using Silverlight 2, application settings are stored locally on the user's computer
To create an application settings dictionary and add an entry
•Create a new instance of the IsolatedStorageSettings class
•Call the Add method to add a key/value pair into the dictionary.
To retrieve a value from the application settings dictionary
•Reference the key and assign a new value
To delete an item in the application settings dictionary
•Call the Remove method and pass the key of the item to remove, as shown in the following example
•appSettings.Remove("email");

 Basics of the Security Policy System

Flash policy file
• The existing crossdomain.xml policy file used by Adobe Flash.
•This policy file can only be used by the WebClient and HTTP classes in the System.Net namespace.
•A Flash policy file must allow access to all domains to be used by the Silverlight 2 runtime.

Silverlight policy file
•The Silverlight policy file that can be used by the WebClient and HTTP classes in the System.Net namespace and also by the sockets classes in the System.Net.Sockets namespace.
• This policy file has a different format than the Flash policy file.



Two primary means for networking applications


Potential Networking Threats
Denial of Service (DoS) attacks
• A large number of remote hosts are used to attack a target site so that the target is unable to service valid requests.
DNS Rebinding attacks
•Use DNS to force a remote host to rebind a trusted host name (site of origin) to a victim’s IP address, thus allowing access to a host other than site of origin.
Reverse tunnel attack
•Use a remote client’s outgoing connection as a back tunnel to the client’s private network.

Sockets security

•Silverlight offers support for the sockets communication.
security considerations and restrictions when communicating with sockets
•Working with Sockets Describes the managed implementation of the sockets networking interface.
•Network Security Access Restrictions in Silverlight 2 Describes sockets and the security policy system in Silverlight.

HTTP security

•Silverlight supports same-domain and cross-domain calls to Web services.
• Cookies and authentication are sent with all HTTP requests.
•for security reasons, Silverlight has restrictions on the types of messages that can be sent and received with HTTP.

HTTP Communication and Security with Silverlight Describes several HTTP communication scenarios and how you can enable these scenarios.
Network Security Access Restrictions in Silverlight 2 Describes how to use the security policy system in Silverlight and describes the policy file formats that are supported.
URL Access Restrictions in Silverlight 2 Describes how the Silverlight runtime restricts access to certain classes of URLs.
Making a Service Available Across Domain Boundaries Describes the mechanisms that Silverlight supports to opt-in to cross-domain access.
Security Considerations for Service Access Describes security considerations when using Silverlight with Web services