Enabling WordPress Permalinks in Windows



Permalinks (pretty-urls) may not work straight away if WordPress is installed on a Windows server.

For many years, I thought it was impossible to have permalinks on Windows server based WordPress.

There are many tricks to enable it on Windows. But this particular one has worked very easily for me because my host is providing Plesk control panel to change PHP settings.

Here is what I did. Plesk allows php scripts to to run as CGI application, FastCGI application or ISAPI extension.

To make permalinks work, just choose ISAPI application as shown below. That’s it.

Wordpress-Permalinks-Plesk-ISAPI-Extension

Thanks.



Spell-check web pages in Firefox



I must write about this as I badly needed a Firefox extension to spell check active web page. However, I couldn’t find one as I was using the latest Firefox version and the extensions did not support the latest version.

Thanks to Alex for the tip. To spell check the current web page, just paste the following line in your browser’s address bar and hit Enter key. That’s it. You will see the magic.

javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

If you are going to use this feature often, just create a bookmark with the above line as the URL.

Thanks.



Installing multiple Internet Explorer versions



You don’t have to. :)

If you wish to test your website in different Internet Explorer versions, you don’t have to install different Internet Explorer versions on your computer. In fact, you can install multiple versions on a single system.

Here is the tool called IETester . This is one  cool software that lets you to test your website on different versions of Internet Explorer.

Here is what their website says:

IETester is a free WebBrowser that allows you to have the rendering and javascript engines of IE9 preview, IE8, IE7 IE 6 and IE5.5 on Windows 7, Vista and XP, as well as the installed IE in the same process

Thanks.



Redirecting old urls to new in ASP.Net MVC



Recently I migrated my classic ASP website to ASP.Net MVC. However, there were many websites still linking to specific .asp pages that no longer exist. I looked for some help on Google so that I could easily redirect the legacy URLs to the new one.

Thanks to Mikesdonetting post that gave me that ‘real code’. You will need to read this post for clear understanding.

While the above post covers the most important aspect of redirecting (LegacyUrlRoute class), I have modified the code so that it suits a more common scenario.

Here is the code:

namespace www.Helpers
{
    class RedirectRule
    {
        public string OldUrlContains;
        public string OldUrlContainsNot;
        public string NewUrl;
 
        public RedirectRule(string strOldUrlContains, string strOldUrlContainsNot, string strNewUrl)
        {
            OldUrlContains = strOldUrlContains;
            OldUrlContainsNot = strOldUrlContainsNot;
            NewUrl = strNewUrl;
        }
    };
 
 
    public class LegacyUrlRoute : RouteBase
    {
        RedirectRule[] RedirectRules =
        {
            new RedirectRule("Notezilla/default.asp", "", "/Notezilla"),
            new RedirectRule("RecentX/default.asp", "", "/RecentX"),
        };
 
 
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            const string status = "301 Moved Permanently";
            var request = httpContext.Request;
            var response = httpContext.Response;
            var legacyUrl = request.Url.ToString();
            var newUrl = "";
 
            foreach (RedirectRule rule in RedirectRules)
            {
                //if we don't have to check for a string that does not exist in the url
                if (rule.OldUrlContainsNot.Length == 0)
                {
 
                    //this does a case insensitive comparison
                    if (legacyUrl.IndexOf(rule.OldUrlContains, 0, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        newUrl = rule.NewUrl;
                    }
                }
                else
                {
                    //if we don't have to check for a string that does not exist in the url
                    if ((legacyUrl.IndexOf(rule.OldUrlContains, 0, StringComparison.CurrentCultureIgnoreCase) >= 0)
                        //so that it doesn't go in infinite loop since the end part of both urls are same
                        && (!(legacyUrl.IndexOf(rule.OldUrlContainsNot, 0, StringComparison.CurrentCultureIgnoreCase) >= 0)))
                    {
                        newUrl = rule.NewUrl;
                    }
                }
 
                //found anything?
                if (newUrl.Length > 0)
                {
                    break;
                }
 
            }
 
 
            if (newUrl.Length > 0)
            {
                response.Status = status;
                response.RedirectLocation = newUrl;
                response.End();
            }
 
            return null;
        }
 
        public override VirtualPathData GetVirtualPath(RequestContext requestContext,
                    RouteValueDictionary values)
        {
            return null;
        }
    }
 
 
}

Here is the explanation:

RedirectRule is a class that holds 1) the old url substring that we much check for, 2) the old url substring that should not exist in the url and 3) the new url which the user must be redirected to.

We initialize an array of such RedirectRule objects and check (inside the function GetRouteData) if the active url matches the criteria given in each rule. If it matches then we redirect to the new url.

Let us see, when we will have the case where RedirectRule.OldUrlContainsNot will need to be used.

Imagine that the old Url was ‘Notezilla/NotezillaSetup.exe’ and the new Url is ‘/Downloads/Notezilla/NotezillaSetup.exe’. In our case if we just check for the old Url then we will end up in infinite loop since the end part of both old and new Url is same (Notezilla/NotezillaSetup.exe). For this reason we need OldUrlContainsNot. In this case we will set OldUrlContainsNot to ‘/Downloads’ so that we do not get in to infinite loop.

Once you are done with the above code just add LegacyUrlRoute to existing routes in Global.asax.cs

 
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
    routes.Add(new LegacyUrlRoute());
}

That’s it.

Thanks.



Moving SQL Server database to another drive/folder



You may find many pages describing how to move sql server database to another location. But a beginner may wonder what needs to be done with the following commands:

use master
go
sp_detach_db ‘mydb’
go

Basically, the above commands are just a set of queries to be run from within a tool like “Microsoft SQL Server Management Studio Express”.

KNOW WHERE THE DATA FILES ARE

In order to move the database, first you will need to know where they are currently stored. This you can find by right clicking on the database in Object Explorer and choosing Properties. In the Properties window you will find the details under the ‘Files’ pane.

Notice the path of your database and open that folder in Windows Explorer so that you can move the data files after detaching the database in the below steps.

DETACHING THE DATABASE

1. Run Microsoft SQL Server Management Studio Express
2. Connect to the required SQL Server
3. Go to File->New and choose “Database Engine Query”
4. Paste the following commands (of course you need to replace the mydb with your database name)

use master
go
sp_detach_db ‘mydb’
go

5. Choose ‘Execute’ from the toolbar. That’s it. This will detach the data files from the database.

MOVING THE DATA FILES

Now, move the data files (*.mdf and *.ldf) to a new drive/folder.

ATTACHING THE DATABASE

To attach the files with the database, replace the previous commands with the following commands and execute.

use master
go
sp_attach_db ‘mydb’,’E:\newlocation\mydbdata.mdf’,’E:\newlocation\mydblog.ldf’
go

VERIFYING THE DATABASE

To check whether attaching was successful, replace the previous commands with the following commands and execute.

use mydb
go
sp_helpfile
go

That’s it. Thanks. Hope this post is clear. If not please do let me know.



Redirecting .asp to aspx in ASP.Net MVC



I am learning ASP.Net MVC and I am loving it.

In the process of migrating our existing classic asp website to ASP.Net MVC we realized that we would still need an .asp file as part of the web app. It’s the redirect.asp file that all our products call to go to different parts of our website.

Fortunately, ASP.Net MVC provides a neat way to do this without actually creating an .asp file. You can route the .asp call to .aspx (MVC View) and have all your code in ASP.Net MVC controller.

Go to Global.asax.cs and write the following code:

routes.MapRoute("Redirect", "redirect.asp", new { controller = "Home", action = "Redirect" });

That’s it.

Note that the redirect.asp file should not (and does not) exist. The routing engine would just route the call to an action that you specify.

Thanks.



WebsiteSpark – A great program from Microsoft



This is one great news. Microsoft has introduced a new program called WebsiteSpark(similar to Bizspark, Dreamspark programs).

WebsiteSpark is designed for independent web developers and web development companies that build web applications and web sites on behalf of others. It enables you to get software, support and business resources from Microsoft at no cost for three years, and enables you to expand your business and build great web solutions using ASP.NET, Silverlight, SharePoint and PHP, and the open source applications built on top of them.

Learn more about it on ScottGu’s blog.

Thanks.



Emulate mobile browser in Firefox



Imagine that you are developing some pages specific for a particular mobile device model (iPhone, BlackBerry etc). How would you test it ?

Here is a nice Firefox plug-in which lets you specify the user-agent to be used when browsing Internet. Based on the user-agent your web pages will be rendered differently.

Here are the details: http://techie-buzz.com/tips-and-tricks/emulate-mobile-browser-in-firefox.html

Thanks