Maximum Capacity Specifications for SQL Serve 2008

by Vahid 1. December 2009 09:18

 it has been always a question for me that  what the maximum number of table in a sql server database is. searching for an answer to this question, i came across the following table in msdn. i found it very usefull and thought of sharing it with you.

SQL Server Database Engine object

Maximum sizes/numbers SQL Server (32-bit) Maximum sizes/numbers SQL Server (64-bit)
Batch size1 65,536 * Network Packet Size 65,536 * Network Packet Size
Bytes per short string column 8,000 8,000
Bytes per GROUP BY, ORDER BY 8,060 8,060
Bytes per index key2 900 900
Bytes per foreign key 900 900
Bytes per primary key 900 900
Bytes per row8 8,060 8,060
Bytes in source text of a stored procedure Lesser of batch size or 250 MB Lesser of batch size or 250 MB
Bytes per varchar(max), varbinary(max), xml, text, or image column 2^31-1 2^31-1
Characters per ntext or nvarchar(max) column 2^30-1 2^30-1
Clustered indexes per table 1 1
Columns in GROUP BY, ORDER BY Limited only by number of bytes Limited only by number of bytes
Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement 10 10
Columns per index key7 16 16
Columns per foreign key 16 16
Columns per primary key 16 16
Columns per nonwide table 1,024 1,024
Columns per wide table 30,000 30,000
Columns per SELECT statement 4,096 4,096
Columns per INSERT statement 4096 4096
Connections per client Maximum value of configured connections Maximum value of configured connections
Database size 524,272 terabytes 524,272 terabytes
Databases per instance of SQL Server 32,767 32,767
Filegroups per database 32,767 32,767
Files per database 32,767 32,767
File size (data) 16 terabytes 16 terabytes
File size (log) 2 terabytes 2 terabytes
Foreign key table references per table4 253 253
Identifier length (in characters) 128 128
Instances per computer 50 instances on a stand-alone server for all SQL Server editions except for Workgroup. Workgroup supports a maximum of 16 instances per computer.SQL Server supports 25 instances on a failover cluster. 50 instances on a stand-alone server.25 instances on a failover cluster.
Length of a string containing SQL statements (batch size)1 65,536 * Network packet size 65,536 * Network packet size
Locks per connection Maximum locks per server Maximum locks per server
Locks per instance of SQL Server5 Up to 2,147,483,647 Limited only by memory
Nested stored procedure levels6 32 32
Nested subqueries 32 32
Nested trigger levels 32 32
Nonclustered indexes per table 999 999
Number of distinct expressions in the GROUP BY clause when any of the following are present: CUBE, ROLLUP, GROUPING SETS, WITH CUBE, WITH ROLLUP 32 32
Number of grouping sets generated by operators in the GROUP BY clause 4,096 4,096
Parameters per stored procedure 2,100 2,100
Parameters per user-defined function 2,100 2,100
REFERENCES per table 253 253
Rows per table Limited by available storage Limited by available storage
Tables per database3 Limited by number of objects in a database Limited by number of objects in a database
Partitions per partitioned table or index 1,000 1,000
Statistics on non-indexed columns 30,000 30,000
Tables per SELECT statement Limited only by available resources Limited only by available resources
Triggers per table3 Limited by number of objects in a database Limited by number of objects in a database
Columns per UPDATE statement (Wide Tables) 4096 4096
User connections 32,767 32,767
XML indexes 249 249

Tags:

Learning resource | SQL | Technical

Export to PDF, Excel and Image in asp.net

by Vahid 18. July 2009 19:48

recently in our project we had a requirement to export html to PDF in asp.net. there are so many components around which we can use to do this but the restriction for us was that we had to do it without spending money means we had to go for an open source component. doing so much I&D on this, we came to know about itextSharp which is a powerful open source component to create PDF files in .net. first it seemed good to us but spending sometimes on it we came to know it was not what we were looking for. two reason for that:

  1. it requires a big learning curve
  2. it’s not at all easy to work with

then the idea of using crystal report came to our mind. we could build the report in crystal report, load it through code without showing anything to user and through it’s API calling the export to pdf function. but it did not work since we had to run some setup components on the live server which we are not allowed to do.

meantime i just remembered we have rdlc reports in .net framework and also Microsoft report viewer. since these are .net component we don't have to install anything on the production server and Xcopy of the required assemblies will work for us. normally you can deploy the .net report files (.rdlc) using xcopy but in order to be able to use the reports you need to install Microsoft report viewer redistributable package which is freely available to download and distribute. this is fine when you have the rights to install components on the server. anyways spending sometime on this technology i found the files required to make the functionality up and running. if you don't want to install report viewer component you need to put these four dll in your bin folder:

Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.ProcessingObjectModel.dll
Microsoft.ReportViewer.WebForms.dll
Microsoft.ReportViewer.WinForms.dll


you can download the files from here:
http://cid-c1dc0bf06aa2e3a6.skydrive.live.com/self.aspx/BlogFiles/ReportViewerFiles.zip

you need to create a report file by click on add new item in your project and selecting Report. then you need to design your report in visual studio as desired. you can use report parameters as placeholder for the values to be passed to to report.

then you need the following lines of code to export:

string[] streamids;
string mimeType;
string encoding;
string extension;
string fileFormat = "PDF";//can also be "Excel" or "Image";
Microsoft.Reporting.WebForms.LocalReport localReport = 
new Microsoft.Reporting.WebForms.LocalReport();
localReport.ReportPath = Server.MapPath("Report1.rdlc");
Microsoft.Reporting.WebForms.Warning[] warnings;
byte[] bytes = localReport.Render(
fileFormat, null, out mimeType, out encoding,
out extension,
out streamids, out warnings);
System.IO.FileStream fs = 
new System.IO.FileStream(Server.MapPath("output.pdf"),
System.IO.FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
Response.Redirect("output.pdf");

remember you can export to PDF, Excel and Image

you can use this method both for asp.net applications and windows application.

hope this comes handy for you.

Tags: , ,

.Net | Technical

Oracle Connection String Without tnsnames.ora file for .net

by Vahid 12. July 2009 04:51

ever wanted to connect to an oracle database in your .net application (asp.net, windows client ect) but tnsnames.ora file was missing? ok,i just found a solution for this in connectionstrings.com. you can use the following connection strings to connect to an oracle database using both microsoft .net provider for oracle database and odp.net:

.NET Data Provider for Oracle

SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=yourHost)(PORT=yourPort))(CONNECT_DATA=(SERVICE_NAME=yourOracleSID)));uid=yourUsername;pwd=yourPassword;

Oracle Data Provider for .NET / ODP.NET

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

Tags: , ,

.Net | Technical

Managing Multiple Configuration File For Different Application Life cycles In .Net Applications

by Vahid 25. May 2009 16:50

All of us have already dealt with the problem of promoting configuration files in different application life cycles. this problem can be as simple as managing different connection strings for different databases in each environment to managing the other complicated settings in each environment.

so many times it happens that we forget to update the configuration file (web.config or app.config) before promotes. what we had already done was to keep one configuration file for each environment (development, testing, staging …) and after promote before build overwrite the the existing configuration file. but even in this case we used to miss to update the configuration file with the latest information. anyway i came across the very good solution in Scott Hanselman's blog. ok here is the solution.

  1. In your project Click the configuration management dropdown and select "Configuration Manager."image

You'll probably have Debug and Release configurations, but you can also make custom ones and base them on existing configuration. In this dialog I've made a new "Deploy" and I'll base it on the "Release" configuration.

WindowClipping (8)

Make sure to create a Solution Configuration AND a Project Configuration, as they are different. Here I've made one called Deploy for the Project also. If you get an error message, be aware of the "Create new project configurations" checkbox. You might get a warning if you are making a new configuration and the dialog tries to make another configuration with the same name; uncheck the checkbox if that happens. Of course, you can have as many Configurations as you'd like.

deploy

2. Add some custom configuration stuff in web.config, like connectionStrings:

	   1: <connectionStrings>
	
	   2:     <add name="Foo"
	
	   3:          connectionString="Data Source=localhost;Initial Catalog=DatabaseName;
	
	   4:                            User Id=sa;Password=debug;"
	
	   5:          providerName="System.Data.SqlClient" />
	
	   6: </connectionStrings>
	

See now I've made the password in my nonsense connectionString = "debug"? Now, create three new web.config's by CTRL-dragging the web.config on top of the project. Name them web.config.debug, web.config.deploy, and web.config.release. Make the password equal to "deploy" and "release" respectively.

WindowClipping (10)

3. Ok,  now we've got different configuration and different configuration files. Let's create a batch file called "copyifnewer.bat" and here's the contents:

	   1: @echo off
	
	   2: echo Comparing two files: %1 with %2
	
	   3:  
	
	   4: if not exist %1 goto File1NotFound
	
	   5: if not exist %2 goto File2NotFound
	
	   6:  
	
	   7: fc %1 %2 
	
	   8: if %ERRORLEVEL%==0 GOTO NoCopy
	
	   9:  
	
	  10: echo Files are not the same.  Copying %1 over %2
	
	  11: copy %1 %2 /y & goto END
	
	  12:  
	
	  13: :NoCopy
	
	  14: echo Files are the same.  Did nothing
	
	  15: goto END
	
	  16:  
	
	  17: :File1NotFound
	
	  18: echo %1 not found.
	
	  19: goto END
	
	  20:  
	
	  21: :File2NotFound
	
	  22: copy %1 %2 /y
	
	  23: goto END
	
	  24:  
	
	  25: :END
	
	  26: echo Done.
	

Basically this batch file will copy a file over another if the files don't match. It's not strictly "copyifnewer" (like, not at all) but it does the job.

Why bother with a batch file to check for changes and not just copy over the file every time? Well, each time you copy over a web.config it restarts all the designers and running AppDomains that are watching that file. No need to copy over a file if it hasn't changed...everything will churn less.

Put this copyifnewer.bat file in the root of your project.

WindowClipping (10)

4. Create a Pre-build Event. Right-click on your Project and select Properties. Click Build Events and in the "Pre-build event command line" and enter this value:

	"$(ProjectDir)copyifnewer.bat" "$(ProjectDir)web.config.$(ConfigurationName)" "$(ProjectDir)web.config"
	

Notice the magic dust, the $(ConfigurationName) project variable, that contains "Debug" or "Release" or "Deploy."

WindowClipping (9)

5. Build. Now if you build, you'll see in the Build Output the batch file being run and the files being copied. Because it's a Pre-Build Event it'll be seen in both the Build Output in Visual Studio .NET.

When you build within Visual Studio the currently selected item in the drop-down list is the current configuration.  now you have different configuration file for each build

there is catch here and that is we have to remember that we've got to keep web.config's in sync if there's lots of settings, but we could totally break it apart via "include files."

Tags: , ,

.Net | Technical

Differences between XML and JSON

by Vahid 24. May 2009 05:29

Here are some key differences between JavaScript Object Notation (or JSON), an open and text-based data exchange format, that provides a standardized data exchange format better suited for Ajax-style web applications and XML.

Although Both JSON and XML can be used to represent native, in-memory objects in a text-based, human-readable, data exchange format, but the two data exchange formats are isomorphic—given text in one format, an equivalent one is conceivable in the other.

following tables is a high level comparision between JSON and XML.

Key Characteristic Differences between XML and JSON

CharacteristicXMLJSON
Data types Does not provide any notion of data types. One must rely on XML Schema for adding type information. Provides scalar data types and the ability to express structured data through arrays and objects.
Support for arrays Arrays have to be expressed by conventions, for example through the use of an outer placeholder element that models the arrays contents as inner elements. Typically, the outer element uses the plural form of the name used for inner elements. Native array support.
Support for objects Objects have to be expressed by conventions, often through a mixed use of attributes and elements. Native object support.
Null support Requires use of xsi:nil on elements in an XML instance document plus an import of the corresponding namespace. Natively recognizes the null value.
Comments Native support and usually available through APIs. Not supported.
Namespaces Supports namespaces, which eliminates the risk of name collisions when combining documents. Namespaces also allow existing XML-based standards to be safely extended. No concept of namespaces. Naming collisions are usually avoided by nesting objects or using a prefix in an object member name (the former is preferred in practice).
Formatting decisions Complex. Requires a greater effort to decide how to map application types to XML elements and attributes. Can create heated debates whether an element-centric or attribute-centric approach is better. Simple. Provides a much more direct mapping for application data. The only exception may be the absence of date/time literal.
Size Documents tend to be lengthy in size, especially when an element-centric approach to formatting is used. Syntax is very terse and yields formatted text where most of the space is consumed (rightly so) by the represented data.
Parsing in JavaScript Requires an XML DOM implementation and additional application code to map text back into JavaScript objects. No additional application code required to parse text; can use JavaScript's eval function.
Learning curve Generally tends to require use of several technologies in concert: XPath, XML Schema, XSLT, XML Namespaces, the DOM, and so on. Very simple technology stack that is already familiar to developers with a background in JavaScript or other dynamic programming languages.

JSON is a relatively new data exchange format and does not have the years of adoption or vendor support that XML enjoys today (although JSON is catching up quickly). The following table highlights the current state of affairs in the XML and JSON spaces.

Support Differences between XML and JSON

SupportXMLJSON
Tools Enjoys a mature set of tools widely available from many industry vendors. Rich tool support—such as editors and formatters—is scarce.
Microsoft .NET Framework Very good and mature support since version 1.0 of the .NET Framework. XML support is available as part of the Base Class Library (BCL). For unmanaged environments, there is MSXML. None so far, except an initial implementation as part of ASP.NET AJAX.
Platform and language Parsers and formatters are widely available on many platforms and languages (commercial and open source implementations). Parsers and formatters are available already on many platforms and in many languages. Consult json.org for a good set of references. Most implementations for now tend to be open source projects.
Integrated language Industry vendors are currently experimenting with support literally within languages. See Microsoft's LINQ project for more information. Is natively supported in JavaScript/ECMAScript only.

Tags: ,

Learning resource | Technical

XPath expressions quick reference:

by Vahid 7. May 2009 07:00

  if you work with XML and xpath for sure the reference seems to be a trivial one for you. but if you stop working with xml and xpath for a while you’ll find the reference pretty handy. i personally keep it with me always. hope it also helps you.

the reference xpath expression is for this xml content:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Albums>
   3:   <Album country="USA">
   4:     <title>Empire Burlesque</title>
   5:     <artist>Bob Dylan</artist>
   6:     <price>10.90</price>
   7:   </Album>
   8:   <Album country="UK">
   9:     <title>Hide your heart</title>
  10:     <artist>Bonnie Tyler</artist>
  11:     <price>10.0</price>
  12:   </Album>
  13:   <Album country="USA">
  14:     <title>Greatest Hits</title>
  15:     <artist>Dolly Parton</artist>
  16:     <price>9.90</price>
  17:   </Album>
  18: </Albums>

and here is the quick reference

/Albums

selects the root element

/Albums/Album

selects all the Album elements of the Albums element

/Albums/Album/price

selects all the price elements of all the Album elements of the Albums element

/Albums/Album[price>10.0]

selects all the Album elements with price greater than 10.0

starts with a slash(/)

represents an absolute path to an element

starts with two slashes(//)

selects all elements that satisfy the criteria

//Album

selects all Album elements in the document

/Albums/Album/title | /Albums/Album/artist

selects all the title and artist elements of the Album elements of Albums

//title | //artist

selects all the title and artist elements in the document

/Albums/Album/*

selects all the child elements of all Album elements of the Albums element

/Albums/*/price

selects all the price elements that are grandchildren of Albums

/*/*/price

selects all price elements which have two ancestors

//*

selects all elements in the document

/Albums/Album[1]

selects the first Album child of Albums

/Albums/Album[last()]

selects the last Album child of Albums

/Albums/Album[price]

selects all the Album elements that have price

/Albums/Album[price=10.90]

selects Album elements with the price of 10.90

/Albums/Album[price=10.90]/price

selects all price elements with the price of 10.90

//@country

selects all "country" attributes

//Album[@country]

selects Album elements which have a "country" attribute

//Album[@*]

selects Album elements which have any attribute

//Album[@country='UK']

selects Album elements with "country" attribute equal to 'UK'

 

 

Tags: ,

Technical

Do You Know About T4 (Text Template Transformation Toolkit) Code Generation In Visual Studio?

by Vahid 14. April 2009 03:15
Working with Microsoft products always has some surprises, now be it a defect, missing functionality or an unknown cool new feature. What's the story? Well recently i was listening to a DotNetRocks show in which i heard the word "T4" which is something regarding to code generation in Visual Studio 2008! i was like, what is this? How come that i have not heard it before? Anyway I was really surprised. So as a code generation passionate i did some R&D about it and here is the outcome.  What is T4? T4 is a code generator built right into Visual Studio. To be clear, we HAVE THIS NOW on our system. So now is the right time to introduce code generation to our company. this means If we are doing something twice or more, manually, in our project, we should stop it and generate it instead. However, there is an issue with this technology and that's the fact that Microsoft does not support it completely as of now and this reason why it is kind of hidden in VS. There's no item templates in File | New Item and there's no intellisense or syntax highlighting. However you don't need this, but if you want really get the most out of T4, first, have a look at "T4 Editor Community Edition." That'll get you some basic coloring.

Now, let's start doing something with T4. go into Visual Studio and create a new Console(or any other type) Application and add a Text File. Then rename it something with a .tt extension. You'll get a warning. Click OK

 

Now, look in Solution Explorer at the .tt file. If you're using C#, you'll have a sub .cs file, or if you're using VB, a sub .vb file. That's the file that will hold the result of the generation. This is the same visual metaphor used to the express the template/generated file relationship with .designer files you've seen elsewhere in Visual Studio. If you look in the Properties for the .tt file, you'll see it's using a CustomTool listed as the "TextTemplatingFileGenerator." This custom tool extensibility point is how things like XSD and WSDL code generators hook in to generate their artifacts.T4 can generate any kind of text file, not just code. You can use it in your projects, as above, or you can call T4 from the command-line. In the following example, I use Damien's T4 templates against the sample Chinook Database.

Notice that I've named the .tt file the same as the .dbml, so Damian's code can find it. I also continue to let original LINQ to SQL generate it's .designer.cs file, but make that file's Build Action "None" so it's not ever compiled. That effectively puts Damian's code in charge. Here's a screenshot showing a bit of Damian's T4 template using the syntax highlighting from the Clairus T4 Visual Studio free download. It looks like a lot like ASP.NET Web Forms. The code blocks are where your logic is and outside the code blocks is the template for whatever you want to generate. Notice how Damien gets input and sets output. You have full control; you can read files off the file system, from with your project, etc. He sets the output extension also. In this example his generated file is Chinook.generated.cs.

 

anyway i believe this would be great technology for code generation and we will be hearing much more about it. following are some good resource which i have found in internet and thought of sharing them with you. hope you like them:

*       Creating your first code generator *       Troubleshooting code generation errors *       Debugging code generation files *       Creating reusable code generation templates *       Creating complex code generators *       Reusing code generators on multiple projects *       How to create a simple T4 template *       How to use T4 to generate .config files *       How to use T4 to generate Decorator classes *       How to use T4 to generate CRUD stored procedures *       How to use T4 to generate strongly-typed navigation class in ASP.NET *       How to use T4 to generate strongly-typed AzMan wrapper *       How to generate multiple outputs from single T4 template *       T4 template for generating ADO.NET Entity Framework Stored Procedures  T4 script for generating ADO.NET Entity Framework Views *       T4 template for generating LINQ to SQL Data Context *       T4 template for generating WiX source files *       T4 template for generating SQL view from C# enumeration *       MSBuild task for transforming T4 templates *       T4 template for generating state machines in C# *       T4 Toolbox project in CodePlex

 

Tags: , ,

.Net | Technical

Software development security check list

by Vahid 6. April 2009 17:11

Recentely i have joined a new as a technical architect. the very thing after getting to the domain was to evaluate the team technical capabalities. so i went through some their codes and found some disaster. i can say that nothing is done regarding to security. i still cannot believe what i have seen. but anyway i shared a handy document about application security with them. hope it will be helpfull for them. so i thought of sharing the same document with you.

To build software that meets our security objectives, we must integrate security activities into our software development lifecycle. I used to use a very handy handbook about security check list. This handbook captures and summarises the key security engineering activities that should be an integral part of your software development processes.

This handbook is a quick reference for developers that summarises the key security engineering activities that should be an integral part of software development processes. These security engineering activities have been eveloped by Microsoft patterns & practices to build on, refine and extend core lifecycle activities with a set of security-specific activities. This handbook provides a snapshot view of the steps necessary to perform each activity, references for additional reading about each activity, and a comprehensive set of security checkliststhat you can use as job aids while developing our software. Audience This handbook provides security activity guidance, checklists and question lists for application architects and software developers who want to improve the security of the applications that they develop. Software developers are the primary audience, but the security engineering activities that this handbook summarises are designed to be used by team members from many different disciplines, including business analysts, architects, developers, testers, security analysts and administrators. The handbook is task-based and is centered on key security activities that you should perform at the various stages of the application lifecycle. The question lists and checklists in Part II of the handbook are job aids and
quick reference sheets that software developers should use when designing and implementing solutions.

 you can download pdf format of the book from the follwoing address:

http://download.microsoft.com/documents/uk/msdn/security/The%20Developer%20Highway%20Code.pdf

Tags:

.Net | Learning resource | Technical

The C# Programming Language Version 4.0

by Vahid 4. April 2009 16:02

 browsing in the internet i came across a blog post about the new C# programming language spesifications (C# 4.0) and thought of sharing them with you. hope you like it.

http://software.intel.com/en-us/blogs/2009/03/30/the-c-programming-language-version-40/

Tags:

.Net | Technical

Optimizing Silverlight pages to be search engine friendly

by Vahid 31. March 2009 14:49

recently i was involved in development of an web application whose interface was based on Microsoft Silverlight. as Silverlight is a new technology we had so much challenges to get the job done but out of them the most important one for us was to make the application search engine friendly. so after doing some I&D on it and spending some late night hours on the issue, i got some good references and experiences which i thought of sharing them with you.

This document describes some best practices for search engine optimization of Silverlight applications. These practices are designed to help developers make their Silverlight content discoverable on a search engine results page and to provide an acceptable experience for users who do not have Silverlight enabled.

This document contains the following sections:

Introduction

As we all know The goal of search engine optimization (SEO) is to increase the chances that your page will appear in the main section of the search engine results page (outlined by the red rectangle in Figure 1), not the paid or sponsored results.

Search engine results page.

Figure 1 - Search engine results page

Even though the search landscape is rapidly changing, with multiple competitors continuously improving and evolving how they implement search, SEO relies on some fundamental similarities among search engine algorithms.

Lets Take A Look At How Search Engines Work

Search engines crawl, weight, and index Web page content. Crawling is done by a search robot that traverses the links in a Web site and captures the content. Search engines then use algorithms and heuristics to assign weights to Web pages. This information is used to build the search index, which is used to build a results page based on your query.

The main reason for a Web page to be highly ranked in search engine results is that the words on the page match the keywords that are used to search. The presence of dynamic and nonstandard elements such as script, style, object, and embed tags in the page is a challenge to search engines, and this is an area where they have traditionally not done well.

In this situation, search engines have to do the following:

  • Download linked content and associate it with the source page.
  • Parse, convert, execute, or render elements to obtain the same experience as the user viewing the page in a browser.

Figure 2 is a simplified view of how a search engine works.

A simplified view of the search engine.

Figure 2 - A simplified view of a search engine

Approaches for Developing a Silverlight Application

If you are planning to build a Silverlight application, there are things you can do to make sure that your application is discovered and returned by search engines.

The following are some of the patterns that you can adopt for how your application coexists with the HTML content.

We Should Mix HTML with Silverlight Content

This pattern involves mixing HTML text with Silverlight content in the same page so that it delivers richness in functionality and the native HTML content is consumable by search engines. To do this, consider designing your Silverlight content in such a way that it fits within, or around, a block of text. This looks like a grid of interacting components that fit around HTML text. An advantage of this approach is that it ensures that your Silverlight interactivity is truly supporting the text, rather than hiding otherwise searchable text from search engines. Figure 3 shows a Web page with this approach.

Islands of text and Silverlight interactivity

Figure 3 - Islands of text and Silverlight interactivity

Use HTML Bridge to Generate Silverlight Content Dynamically

This approach is slightly harder to achieve and can be limiting to the Silverlight experience. You will have most success with this approach if you have existing XHTML content and want to enhance the experience with Silverlight. In this approach, the XHTML content is the base experience for search robots and down-level clients, while the Silverlight experience is reserved for consumers on client platforms capable of running Silverlight.

In this approach, the XHTML content has the full-fidelity experience for its target clients. It is still declared as nested alternate content within the object tag for the Silverlight plug-in. The one attribute that differentiates this pattern from the graceful degradation pattern is that in this pattern, the Silverlight application’s UI is driven by the nested alternate content. In other words, application logic will use the DOM Bridge to get the nested alternate content from the object tag and use it to construct the Silverlight UI. This can be as simple as using XSLT to transform the XHTML to XAML, or perhaps using data binding to bind XAML UI properties to an object representing content from the extracted markup.

Graceful Degradation

In this document, we focus primarily on search engine optimization using the graceful degradation approach. In such a scenario, the Silverlight content is the primary experience for consumers, and the use of nested alternate content within the object tag serves as the down-level experience.

Search Engine Optimization Techniques for Silverlight Applications

The key consideration for making Silverlight content indexable by search engines is to use the approaches that are used for systems and users for which Silverlight is not enabled. Considerations include the following:

  • How the Web page with Silverlight content behaves in client/browser configurations such as Opera or Windows 98, which are not currently supported by Silverlight.
  • How the Web page behaves for customers who use accessibility programs such as screen readers and narrators.
  • How the Web page behaves for customers who use from a text browser such as Lynx, where no scripts can execute.

Presenting contextual metadata and alternate content that would make Silverlight content friendly to down-level users will also make it friendly to search engines.

When creating your Silverlight application, do not assume that all users will have Silverlight installed or have computers with the ability to install Silverlight. Prepare for how you would describe your application to these users.

  • Know your audience.
  • Plan on how you would describe your application to them.
  • Identify the keywords that you would use to connect with searchers.

The words that you use in your titles, page and section headers, body content, and alternate content play an important role in how the search engines find and index your content, and also how a user finds your content.

The following are some of the techniques you can use to optimize your search engine results and improve the experience for all users:

Use a Descriptive Page Title

Give your page a good title. Web page authors must update and customize the markup in the pages generated by Silverlight project templates in Visual Studio or Expression Blend. For the purposes of discussion, let’s assume you have a Silverlight application that provides interactive traffic maps for the Seattle area. Figure 4 shows bad (default) and good Web page titles.

Bad and good page titles

Figure 4 - Bad and good page titles

Add Description Metadata

Keywords in your page’s meta tag are not very useful for search engines to determine your page’s rank. However, a page title and meta description tag (that is, a meta tag whose name attribute is set to "description") are extremely useful in ensuring that searchers who view your page on a results page associate it with content that they are looking for.

If you have a top-level Silverlight application that occupies the full extent of the browser’s client area, or one that exists on your landing page, then you must have a meta description tag on your HTML page. The following code shows the format of the meta description tag.

<head> <meta name="description" content="Microsoft portal site for the Silverlight development community..." > ... </head>

If you have a page with a lot of text content that contains relevant keywords, then you can omit the meta description. The search engine will show a portion of your page content on the results page, and any stub description may actually prove counterproductive.

The following figure shows a sample search page entry with a description, and how it would appear if the meta description tag were not present.

Search results page with and without a meta description tag

Figure 5 - Search results page with and without a meta description tag

Use a Meaningful Application Name

Giving a useful name to your application is another way to help the search engines find your Web page. For example, an application that provides traffic maps for the Seattle area could be named SeattleTrafficMaps.xap.

Even if your application was built using a different name, it is easy to change the name, for example, from MyTestSLApp.xap to SeattleTrafficMaps.xap. Changing the name back at a later time is a simple operation if that name is not referred to elsewhere in your code. By default, there are no dependencies of this kind in the Silverlight templates.

Use the object Tag

The object tag in HTML is designed so that if the main object cannot be loaded to display content, then browser clients will continue to look for alternative content within the object tag.

Silverlight content publishers must use the object tag (not the embed tag) to instantiate Silverlight. The following code shows how you can add the object tag.

<object type="application/x-silverlight-2" data="data:application/x-silverlight," width="..." height="..."> <param name="source" value="SeattleTrafficMaps.xap" /> <!-- Other parameters, if any --> ... <!-- The “Get Silverlight” messages and badge --> <p>This content requires Microsoft Silverlight. <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </p> </object>

Specify Alternate Content for Silverlight

The object tag for the Silverlight application must be supplemented with nested alternate content, namely the inner HTML that is displayed on systems where Silverlight is absent. The following code shows how you can do that.

<object type="application/x-silverlight-2" data="data:application/x-silverlight," width="..." height="..."> <param name="source" value="SeattleTrafficMaps.xap" /> <!-- Other parameters, if any --> ... <!-- Nested alternate HTML content for search --> <h3>Traffic map of the Seattle-Puget Sound area</h3> <p>Up-to-the-minute traffic situation overlaid on the map of the Seattle-Puget Sound area, powered by <a href="http://maps.live.com">Live Maps</a> </p> <!-- Canned image representing the application contents --> <img src="SeattleTraffic_RushHour.jpg" alt="Seattle traffic at 5:30pm (evening rush-hour)" /> <!-- The “Get Silverlight” message and badge --> <p>This content requires Microsoft Silverlight. <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </p> </object>

Use createObject When Using Silverlight.js

The primary function of Silverlight.js is to provide a cross-browser, cross-platform means of constructing the right markup to get Silverlight content hooked up to the HTML DOM. Typically this involves working around browser quirks to generate the object tag with the right set of parameters. The createObject function also takes the id of a parent element, for example a div or span, within which the Silverlight object will be hooked up as child element. This approach uses the following logic.

if (slParentElement != null) { slParentElement.innerHTML = slPluginHTML; }

For example, assume that your markup consisted of the following code.

<div id="divWithinWhichSLObjectExists"> <script type="text/javascript"> Silverlight.createObject("slObjectId", "divWithinWhichSLObjectExists", ...); </script> </div>

The effective DOM would be like the following code when executed on the browser.

<div id="divWithinWhichSLObjectExists"> <object type="application/x-silverlight-2" data="data:application/x-silverlight," width="..." height="..."> <param name="source" value="SeattleTrafficMaps.xap" /> <!-- Other Parameters, if any --> ... <!-- The “Get Silverlight” message and badge --> <p>This content requires Microsoft Silverlight. <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </p> </object> </div>

This has a beneficial side effect for the following reasons:

  • Replacing the inner HTML of the parent div removes any other existing child elements in that div.
  • Search engines often parse and index markup as it is served—before any scripts execute and change the DOM.

In other words, you can add detailed contextual metadata as native HTML within the parent div element of the Silverlight object. Search engines will process the metadata, but the metadata will not show up in the browser.

If your parent div has nested contextual content, the following code is what the search robot sees.

<div id="divWithinWhichSLObjectExists"> <!-- Nested alternate HTML content for search --> <div> <h3>Traffic map of the Seattle-Puget Sound area</h3> <p>Up-to-the-minute traffic situation overlaid on the map of the Seattle-Puget Sound area, powered by <a href="http://maps.live.com">Live Maps</a> </p> <!-- canned image representing app contents --> <img src="SeattleTraffic_RushHour.jpg" alt="Seattle traffic at 5:30pm (evening rush-hour)" /> </div> <!-- Invocation of the createObject function in Silverlight.js --> <script type="text/javascript"> Silverlight.createObject("slObjectId", //SL plug-in id "divWithinWhichSLObjectExists", //parent id ...); </script> </div>

Test Down-Level Experiences

Regardless of the relative importance of Silverlight and HTML in your content, it is important to test the page as a user who does not have Silverlight installed.

To access the page as a down-level user, perform the following steps:

  1. Close all instances of Internet Explorer, and then start a new instance.
  2. On the Tools menu, point to Manage Add-ons, and then click Enable or Disable Add-ons. The Manage Add-ons dialog box is displayed.
  3. Select Microsoft Silverlight, select the Disable button, and then click OK.
  4. Restart Internet Explorer and navigate to the Web page that has your Silverlight content.

To revert, return to the Manage Add-ons dialog box, select Microsoft Silverlight, and select Enable.

Note

The procedure for temporarily disabling the Silverlight plug-in differs depending on the browser you are using.

After you have tested the down-level experience, it is worthwhile validating your page with a static analysis tool such as SEO Browser that understands the impact of markup and content on search engine optimization.

Conclusion

The ability of search engines to index content that is not native HTML is very limited. However, if you structure and present your Silverlight application in certain ways, they have a better chance of appearing on a search engine results page in response to a search query.

Tags: , ,

.Net | Learning resource | Technical