Monday, November 27, 2006

Migration from Atlas July CTP to ASP.NET Ajax Beta 2

I am developing an application which does not really make use of Atlas controls but has a significant amount of Atlas scripting code to migrate.

I am not found of declarative scripting but maybe I am old-fashioned: I like to step through my code to debug it. My opinion is that declarative scripting is only good as the output of code-generation tools. It is not something that developers should write in a text editor.

So, I have got script to migrate and I have read the documentation available at:

Downloading and installing ASP.NET Ajax Beta 2 is well explained in the documentation but I had to do a bit of guessing as well as exploring Microsoft’s code to migrate my own code. I deliver my findings below:

Migrating client script

  1. To use client scripting of html components, you need to add a reference to PreviewScript.js in your ScriptManager as shown below:

<asp:ScriptManager ID="ScriptManager" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview"
Name="Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js"/>
</Scripts>
</asp:ScriptManager>

  1. $(id) is now $get(id)

  2. The Sys.UI namespace is now Sys.Preview.UI

  3. Sys.UI.Select is now Sys.Preview.UI.Selector

  4. Sys.UI.CheckBox.click.add(handler) is now Sys.UI.Preview.CheckBox.add_click(handler)

  5. Sys.UI.Select.selectionChanged.add(handler) is now Sys.Preview.UI.Selector.add_selectionChanged(handler)

  6. $addHandler/$removeHandler is the new way to add event handlers

  7. Sys.UI.Control.get_enabled() and set_enabled() no more work

Migrating web service calls

  1. You need to decorate your web services and page methods with new attributes as explained in http://blogs.msdn.com/sburke/archive/2006/10/21/hint-components-that-use-web-services-with-asp-net-ajax-v1-0-beta.aspx.

  2. The prototype of asynchronous calls to web services and page methods has been simplified, but this is well explained in the documentation listed above.

Friday, November 24, 2006

How to configure the IIS SMTP Service to send emails from ASP.NET code?

I have probably configured the IIS SMTP service a dozen times over the past five years but I still struggle with authentication and relay, so I have decided to write this note once and for all.

First, the source for your System.Net.Mail issues is definitely http://www.systemnetmail.com/, including some sample code.

Because we are all urged to deliver rapidly, I have provided a test application which you can download from http://www.velodoc.com/downloads/061124.blog.zip. Contrary to most samples that you will find on the Internet, this one uses a configuration file including system.net\mailSettings, which is probably the way you want to send emails from your ASP.NET code.

Obviously you need to install the SMTP Service, which is well explained at http://msdn2.microsoft.com/en-us/library/8b83ac7t.aspx.

Let’s say you need to send your emails from website@yourdomain.tld. In this case, it is recommended (but not required) that you rename the default domain into yourdomain.tld.

Display the default SMTP Virtual Server properties and on the Access tab:

  1. Configure authentication by removing Anonymous access and allowing Basic authentication and/or integrated Windows authentication;
  2. Grant relay to 127.0.0.1 and allow all computers which successfully authenticate to relay.


You can certainly be more restrictive depending on your requirements, once you got teh above configuration to work properly.

Finally, you can create a dedicated account and properly configure your settings:

<system.net><mailSettings>
<smtp deliveryMethod="Network" from="website@yourdomain.tld">
<network host="127.0.0.1" port="25" userName="DOMAIN\account" password="password"/>
</smtp>
</mailSettings>
</system.net>

What’s next after designing and hosting your web site?

You have now designed a nice web site which you have uploaded on a hosted server and you think you are ready to go. Not quite right. There are a few more steps required which will guarantee a better visibility of your web site.

I am not a search engine optimization (SEO) professional and qualified people are writing books about SEO which can be a very complex subject. But I have been confronted to the issue, I have searched for answers on the Internet and I publish here my findings. If you apply the 80-20 Pareto rule, you can get decent results in three steps that you may want to re-iterate periodically:

  1. Make your web site is right for search engine crawling robots;
  2. Submit your web site to search engines;
  3. Get referral links.

I may have done something right since I have managed to get our web site on the first page on MSN and Yahoo. I know from experience that the only way to get a high ranking on Google is to obtain referral links.

1) Make your web site right

First, you need to make sure that search engine robots can read your web site. You also need to assist search engine robots by telling them which pages to index and how to categorize your web site.

Make sure your HTML is compliant

A web design environment like Dreamweaver will warn you of any non-compliance issue. You can also use a text browser like Lynx to check that your web site displays properly to search engines. Note that search engine robots read sites in a similar way. You can also check your pages at http://www.smart-it-consulting.com/internet/google/googlebot-spoofer/index.htm.

Important also is to set the page encoding and content language. I personally recommend using utf-8 encoding even on English pages. Contrary to what people often think, utf-8 is not double byte and the size of an English page is the same in utf-8 and iso-8859-1.

Describe your web site properly

Title, meta description, meta keywords and images alternate text contribute to help search engines categorize your web site properly.

Getting your keywords right is a difficult exercise:

  1. you should limit yourself to 10 to 20 keywords;
  2. the more targeted your keywords the more efficient they are to help find you, but you do not want to be too narrow;
  3. As far as Google, Yahoo and MSN are concerned, you do not need both the singular and plural of a keyword and the order of words in a keyword seems to make no difference.

The following tools will help your build your keywords meta tag:

Add an address and a privacy policy

An address and a privacy policy will not give you a high ranking, but they may prevent you from getting one because you won’t look like a serious company. To add a privacy policy for your site, follow the steps at http://www.the-dma.org/privacy/creating.shtml#form.

Add content rating

To add content rating for your site, follow the steps at http://www.icra.org/label/

Create sitemaps

Sitemaps will tell search engines which pages to look for. To create sitemaps, follow the steps at http://www.xml-sitemaps.com/. You can get more information at http://www.sitemaps.org/.

You are encouraged to submit your sitemaps to search engines, in particular:

Create a robot.txt file

You create a robots.txt file essentially to tell which parts of your site not to index. More information about robots.txt files is available at http://www.robotstxt.org/wc/robots.html.

Add web site monitoring and statistics

If your web site is too often inaccessible, you will be downgraded by search engines. Accordingly, you need to monitor your web site and keep your ISP honest. The following monitoring services range from free to high-end:

Most hosting packages come with AWStats and Webalizer which give poor statistics. There is obviously http://www.webtrends.com/ but I can only recommend the free http://www.google.com/analytics/.

2) Submit your web site to search engines

Most ISPs offer search engine submission standard with hosting packages. Unless you are very lazy, do not pay for a submission service and do not buy submission software. Submitting your URLs to Google, MSN and Yahoo only takes 10 minutes and covers for more than 80% of the search engine traffic.

This is especially true if you already own a web site that is referenced. In this case, you just need a hyperlink from the referenced web site to the new web site and the search engine crawlers will automatically index your new site.

3) Get referral links

Getting referral links is the only thing that guarantees high rankings. Basically, the more a page is referenced on the web, the best the value of this page to the Internet community, so the highest ranking it gets in searches. Additionally, a reference on the http://www.bbc.co.uk/ web site is worth more than a reference on http://www.acme.tf/.

So you need to work on getting other web sites to reference your own web site. This is an everyday job that only your organization can successfully perform. You should get a decent ranking on Google (top 3 pages) with about 100 references but obviously some topics are more crowded than others. The earlier you start the better. Good luck!

Thursday, November 23, 2006

Troubleshooting SMTP using Telnet

Today, I have been confronted to configuring Virtuozzo + Plesk on our new VPS web site server to send emails from ASP.NET code.

On our old Plesk 7 server, we used to send emails from an email account which had no mailbox but the same configuration did not seem to work in the more recent Plesk 7.6. I am not a Plesk aficionado, so I went the old way to find out what was going wrong.
  1. Open a command windows by typing cmd in the Start -> Run… dialog box and click OK.
  2. At the prompt, type telnet mail.yourdomain.tld 25 + Enter
  3. The mail server should display version information.
  4. Type HELO + Enter.
  5. Type AUTH LOGIN + Enter.
  6. Type your mailbox username or username@ yourdomain.tld encoded in base64 + Enter. ESMTP requires a login in the form username@ yourdomain.tld. A helpful site to get a base64 encoded value is http://www.motobit.com/util/base64-decoder-encoder.asp.
  7. Type your mailbox password encoded in base64 + Enter.
  8. If you have successfully authenticated, the server will reply "235 authenticated".
  9. Type MAIL FROM: username@ yourdomain.tld + Enter.
  10. Type RCPT TO: anothermailbox@ yourdomain.tld + Enter.
  11. Type DATA + Enter.
  12. Type Subject: Test + Enter + Enter (Send a blank line to separate the headers from the message body).
  13. Type SMTP test + Enter.
  14. Type . + Enter (a dot, then Enter).
  15. The server should reply "250 Message queued"
  16. Type QUIT + Enter.
  17. Close the command window and check your mailbox.
In my case, the message that I was getting in .NET was “no email account can send to anothermailbox@ yourdomain.tld”, which is not very helpful but the procedure above was showing that step 8 was actually going wrong. After a few changes in the Plesk configuration I have discovered that the email account required a mailbox to send emails.

Translating a web site into Chinese and Japanese

We are a small company selling software as a service. Most of our leads come from advertising on Google, MSN and Yahoo and although we are European, 70% of our customer base is located in the US. This is not surprising because our web site is only available in English and French and our advertising too. Considering that most of our competitors are located in the US too, we can assume that the cost of a lead in the US is much higher. So we have decided to tap into the great reservoir of non English-speaking countries and have our web site translated in 8 languages, among which Chinese and Japanese.

Word documents

We have put our web content into Word 2003 to get it translated by professional translators. Obviously the Chinese and Japanese documents that we have received were not properly displayed in Word. We have found on the web that we had to install the Proofing Tools for Microsoft Office to display the content, which we have done and it works. We have realized later on a computer that had downloaded the Asian language packs for Internet Explorer that this is another way to get the Japanese and Chinese content properly displayed in Office, and contrary to the Proofing Tools, it is free. In fact Word 2003 is Unicode and you just need the proper fonts.

Html pages

The next step is to get the Word document into HTML. Apparently copying and pasting from Word to Dreamweaver works quite well but I have had so many issues in the past with the way Word handles HTML that I have preferred another way. You need to choose whether you will have an UTF-8 encoded page or whether you will use a code page (GB 2312 for simplified Chinese). A code page will produce a more compact file but this is the old way. We have decided to use UTF-8 for our entire site. In Word, save your word document as “filtered html” and in the Save As dialog select “Web options”. Select the UTF-8 encoding and a simplified Chinese font. Do the same for Japanese. Then you can open your new html document in Dreamweaver and copy paste reliably within Dreamweaver.

You will need to add the following meta tags in your translated html pages:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="zh" />

Images

We use Adobe ImageReady and Macromedia Fireworks for our images. Fireworks is less powerful but the use of the PNG file format makes it much easier to maintain large quantities of image files because Windows Explorer displays the thumbnails. When you copy Chinese characters from Word or Html into ImageReady, only half of them display properly and the others are replaced by question marks. In fact ImageReady selects the MS Gothic font by default when it should paste SimHei or SimSon. These fonts are not even displayed in the font drop-down list but you can key in the font name and this works.

Finally, no matter how well you prepare your work with the translators, you will realize that some strings will be too long to fit your buttons or some last minute changes will not have been taken into account or else and you will find much easier to get an approximate automated translation from http://www.systransoft.com/index.html.

You can check the result at http://www.velodoc.com/zh/ and http://www.velodoc.com/ja/. To download the Asian Pack, simply select View -> Encoding -> More -> Chinese Simplified in Internet Explorer.

Wednesday, November 22, 2006

Resumable file downloads in ASP.NET

The http protocol implements the ACCEPT-RANGES and ETAG response headers to signify the ability to download resources in chunks. There is an interesting article published in MSDN magazine which has some sample code implemented in VB.NET. For the records, similar implementations can be found at:
  1. http://www.thescripts.com/forum/thread334139.html
  2. http://www.devx.com/dotnet/Article/22533/0/page/1

I have made a C# implementation of this code which you can download from http://www.velodoc.com/downloads/061122.blog.zip.

To use this code, you need to:

  1. Create a C# class library named “Memba.FileDownload” or whatever name you deem more appropriate and add the two class files from the archive.
  2. Create a web site and add the following to the system.web/httpHandlers section of the web.config:
    <add type="Memba.FileDownload.DownloadHandler, Memba.FileDownload" validate="false" path="*.zip" verb="*"/>
  3. You also need to make sure the zip extension is mapped to the aspnet_isapi.dll in the IIS management snap-in otherwise your handler will not be called.

To test this code, download a zip file hosted on the web site you have just created. You should be able to stop and resume the download in Internet Explorer or any download manager which supports resumable downloads.

Where do you get your icons from?

I have never been able to find a decent royalty-free library of icons but you only have what you pay for, haven’t you?

IconExperience is the best library I have found and I can only recommend it. It is comprehensive and affordable. Incors have just released version 2.0 which has more than 2000 icons and now includes the 128*128 format.

If you know any other valuable source of icons, please comment.