Thursday, January 14, 2010

Enabling GZip Compression in ASP.NET with AJAX

Compression is a very effective way to make your website faster on the web. There are generally two types of compression GZip and Deflate. You can use any of these methods in your asp.net applications.

Compression can be done by changing the settings in IIS or even at the code level by adding a simple piece of code in your global.asax file.

While implementing GZip compression on my website I came across many solutions but all of them had problem with the AJAX features. However, I have used the following code in my global.asax file, and it works perfectly with all AJAX features.


Private Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Dim app As HttpApplication = DirectCast(sender, HttpApplication)
        Dim acceptEncoding As String = app.Request.Headers("Accept-Encoding")
        Dim prevUncompressedStream As IO.Stream = app.Response.Filter
    
If acceptEncoding Is Nothing OrElse acceptEncoding.Length = 0 Then
            Return
        End If
    
        If (Request.Path.EndsWith("axd")) Then
            Return
        End If
        
        acceptEncoding = acceptEncoding.ToLower()
    
        If acceptEncoding.Contains("gzip") Then
            ' gzip
            app.Response.Filter = New IO.Compression.GZipStream(prevUncompressedStream, IO.Compression.CompressionMode.Compress)
            app.Response.AppendHeader("Content-Encoding", "gzip")
        ElseIf acceptEncoding.Contains("deflate") Then
            ' defalte
            app.Response.Filter = New IO.Compression.DeflateStream(prevUncompressedStream, IO.Compression.CompressionMode.Compress)
            app.Response.AppendHeader("Content-Encoding", "deflate")
        End If
    End Sub


In the above code, the following lines are the ones that solve the ajax related issues:




        If (Request.Path.EndsWith("axd")) Then
            Return
        End If



Do let me know if this code works for you.

Friday, October 16, 2009

Selecting a screencasting tool for your project

Recently I was in need of a good screencasting software to create my own video tutorials. I must say that this is one area where a paid software is a much better option than an open-source one. Let us take a look at the available options.

1. Camtasia Studio - Even though I have not used it, all the feedback I have read till now tells me that this is the best screencasting software available. It is however a premium product and will cost you $299. This software comes will all the features that you require, including the much desired video editing features, and glamorous player themes. You can even annotate the video frames with your own text, pointers, etc. It records the screencast in video format, and the output can be in your desired format including flash.

2. Camstudio - This is an open-source software. It is a good alternative to Camtasia Studio but lacks the editing feature. So, once you record something you have to live with it or rerecord the whole thing. This makes it cumbersome for users new to screencasting, as mistakes are bound to happen.

3. Wink - This is another open-source screencasting tool from DebugMode and works pretty well. It comes with all the editing features that you may require. You can add/delete frames, and even overlay text, arrow marks, etc on the screens. I think this is the best tool to start your screencasting experience with As you gain experience, you can thing of purchasing a license for Camtasia Studio.


4. Jing - This is also a free software for screen captures and screencasts. It has a limitation of 5 minutes for recording and also doesn't have editing features. However, the screen capture feature is verygood. You can capture a screen and then even add textboxes, shade different areas, or add arrow marks, among other features.

I am using Jing for screen captures and Wink for screencasting.

Tuesday, September 29, 2009

Building an Online Training Portal Using Drupal

I am currently in the process of building an online training portal for a niche subject that I teach. While there are many options for a content management system there is a need for something very flexible that can be easily adapted to deliver online training.

After going through the documentation and feature list of Moodle, Joomla, and some other softwares I finally settled with Drupal mainly because of the flexibility it offers.

Drupal, in my opinion, is best suited for building a paid membership website, as there are loads of modules available to get you do exactly what you want.

Take the core drupal installation and combine it with certain contributed modules and you have the portal with all the functionality of a paid membership website with shopping cart, member lists, a forum, and a private section for premium content.

Currently I am using the following modules to achive my goals.

1. Drupal core - This sets up the base with membership, pages, menus, forums, search, blog, etc.
2. Ubercart - This shopping cart fully integrates with your Drupal installation. You can sell physical goods, ebooks, or even specific content on your website. It also provides various payment options including credit cards, and paypal.
3. Taxonomy Access Control Lite - This module restricts access so that some users may view content that is hidden from others. A simple scheme based on taxonomy, roles and users controls which content is hidden.

The above modules are just about sufficient to get going. You may want to add more modules for additional functionality depending on what you want your portal to sell or do.

Currently I am using pages to organize the website content, and the Books module (comes with core) to organize the premium content. In another post I will talk about how exactly I am segregating paid content from the rest and how a user gets access to it.

Do comment about what you think about Drupal.

Wednesday, September 9, 2009

Bug tracking and project management with RememberTheMilk

When you run a web portal, one of the important tasks is to track and fix the bugs to come across.

With large project teams this task can be made into a process and tracked through softwares. However, if you have only one programmer working on the portal, then you need a quick and simple solution.

I have been doing this for past few months by either jotting down points in email drafts or on small pieces of paper. Both these methods are very crude because the small paper pieces will invariably get lost or messy.

Today I thought of creating an account with RememberTheMilk and so I did.

I cannot believe this whole thing can be so easy. All I need to do is type my issue and press ENTER, and my task is added. In my case tasks are actually issues and bugs that I come across.

It is a continually updating list so I never have to worry about missing anything. Also, as soon as I am done with a bug fix, I need to check it as completed, and it vanishes from the main list (you can always see it in the completed tasks list).

For each task you can add a time duration, set priority, and a lot more. One of the best things is that for each task you can add notes. This is particularly useful when you are researching solutions for a particular issue. You can take notes of how you want to fix it, add URLs of helpful articles, etc.

I am even using it to put down ideas for my data and content related developments.

One very interesting feature is that you can email tasks to your task list. For each account there is a special email id assigned. If you send an email to this special email id, the email content gets added as a task in your task list (subject line becomes a task, and mail body becomes a note). If you have a feedback/support form on your website, it is a good idea to even cc the form contents to this email id as well in which case the support issue will get added as a task, and then you can never miss it.

Tuesday, September 8, 2009

Migrating from NET 2.0 to NET 3.5

In my last post, I mentioned that I successfully migrated my website from .NET 2.0 to .NET 3.5. Here I will describe how I did it.

Initial preparation:
1. You need to setup the .NET 3.5 environment on you local machine. So, download and install .NET Framework 3.5 and Visual Studio 2008 from Microsoft website. If you have VS 2005 with you, even that will work fine but VS 2008 would be better.

2. Also download the latest version of Ajax Control ToolKit from here. Note that for .NET 2.0 you installed Ajax extentions separately. In .NET 3.5 you don't have to do that. They are automatically included when using ASP.NET AJAX in ASP.NET 3.5 SP1. Only the Control ToolKit needs to be installed separately.

3. Now create a sample application by launching Visual Studio 2008. Apart from other files, the sample application will generate the web.config file, as usual. This file references all .NET 3.5 assemblies and other stuff and is core to your application as well as to the migration process.

4. Add reference to the Ajax Control ToolKit by dropping an Ajax control in the default page or by simply coping and pasting the AjaxControlToolKit dll file in the bin folder (you will have to create the folder as well).

5. Launch the application to see if it is running fine.

Testing on your Host Server
1. Before the actual migration, you need to be sure that your host server will support .NET 3.5. You can ask your host as well as run a test application.

2. Note that the migration will affect mainly your Bin folder and web.config file.

3. Choose a suitable time when you can put your website down. Log into your FTP account and delete the Bin folder and web.config file. Now upload the new Bin folder and the new web.config file, along with a new sample page that you created. Test this sample page on your website. It should work if the hosting server supports .NET 3.5. If it doesn't work, revert back to the older bin folder and the web.config website.

Finally getting it up:

Assuming that the sample page worked, you are now ready to fully migrate to .NET 3.5.

Mainly you are looking at updating the assembly files and the web.config. You need to take the new web.config file and compare it with the older web.config file. Whatever things are common (but have a version difference) just ignore them. Look for custom settings that you might have added to the web.config file such as database connection strings, URL rewriting rules, etc. Copy those addiitional lines of code and paste them in appropriate places in the new config files. Similarly compare the old Bin folder and the new Bin folder. What ever files are common (but may have version difference), don't touch them. Just look for any additional DLLs that your application might be using (any custom or additional DLLs). Copy those additional DLL files to the new Bin folder.

Just for being sure, also check your master page. Some programmers tend to make references to assembly files in master page. If so, you need to update the version based on the version specified in web.config file.

Replace the bin folder and the web.config file in your web application with the new ones. That's it. You are done.

Upload this and you are now running on .NET 3.5!

Happy migration!

Monday, September 7, 2009

Successfully migrated from .NET 2.0 to .NET 3.5

I recently shifted my web hosting from ZNetIndia to GoDaddy.

During the migration I faced a couple of issues one of which was that some of the features were not working and I required me to migrate to .NET 3.5

The website got migrated successfully without any problem and all the features are working just fine. It is such a relief.

In another post tomorrow I will explain what this migration involved and how I did it smoothly.

My web portal and the technologies used

In this post I will give an overview of my web portal and the technologies used so far.

The portal URL is www.PerSquareFeet.in

It is a property portal that provides property classified, reviews and ratings of property builders, architects etc, and lots of information about home loans, home decor, and property buying.

Main website (www.persquarefeet.in): ASP.NET and SQL Server 2005. It also uses Ajax Control Toolkit.

Currently the website is running on ASP.NET 2.0 but I am migrating it to ASP.NET 3.5 in a day or two for the reasons I will speak about after I have successfully migrated.

Blog (blog.persquarefeet.in): The blog runs on wordpress (PHP5 and MySQL5 for those who don't know about technologies behind wordpress). I am currently using wordpress version 2.8

That's all the technology involved.