Blog Archives

URL Rewriting/Mapping using Global.asax

Ultimately I wound up using a different method, specified in my other blog post on URL Rewriting on GoDaddy and Shared hosting.

However, the method below is actually very useful if you are trying to do certain validation which cannot be expressed in web.config or RegEx prior to redirect, such as checking if querystring is valid and exists in database values, etc.

        //try out various request types such as absolute path and raw url to see differences
        protected void Application_BeginRequest(object sender, EventArgs e)
            string originalPath = HttpContext.Current.Request.Path.ToLower();

        private void RewritePaths(string originalPath)
            Rewrite(originalPath, "default", "index");
            Rewrite(originalPath, "home", "index");
            Rewrite(originalPath, "index");
            Rewrite(originalPath, "login");

        private void Rewrite(string path, string page)
            if (path.Contains("/" + page))
                if (!path.Contains(".aspx"))
                    //Context.RewritePath(path.Replace("/" + page, "/" + page + ".aspx"));
                    Context.RewritePath(page + ".aspx");

        private void Rewrite(string path, string frompage, string topage)
            if (path.Contains("/" + frompage))
                if (!path.Contains(".aspx")) {
                //Context.RewritePath(path.Replace("/" + frompage, "/" + topage + ".aspx"));
                Context.RewritePath(topage + ".aspx");

URL Rewriting on GoDaddy and Shared hosting

After doing a lot of searching through google queries, forums and archives, I was finally able to solve the conundrum of using URL rewriting on GoDaddy.

The site in question is also a subdomain in a sub folder off the root site, meaning web.config rules cascade, which complicated things slightly more and was enough to send GD support over the edge.

So my site/domain/DNS setup was as follows:

//--and sub
//--where sub is actually cname of

//--parent points to root folder
//--and sub points to subsite folder
//--desired url
/subsite/default //--should point to /subsite/default.aspx

I could not find a single article which presented a complete solution, including my own URL Mapping solution I presented in a previous article.

The simple solution in my previous article only works on GoDaddy servers if the mapping specifies a file extension on both the url and mapped url, such as:

<urlMappings enabled="true">
            <add url="~/default.aspx" mappedUrl="index.aspx"/>
            <add url="~/index.html" mappedUrl="index.aspx"/>

After speaking with GoDaddy support on 3 separate occasions, including callbacks from higher tiers, they informed me the mappings “work” and deferred to the above example..

So I dropped the simple approach of using URL Mappings, and stepped it up to URL Rewriting. According to GoDaddy kbase article, Microsoft URL Rewriting is supported, although for some reason they don’t include any examples..

I was able to at least get this working as intended after a little tweaking and reading through some of the references listed further below.

The configuration I am using is IIS7 with .Net 3.5. Haven’t tested it on 4.0 though this should work as well.

The solution:

(see code snippets above for domain structure in my scenario)

(( make sure you don't place modules or system.webServer in your web.config more than once.. you'll get a server 500 error :P ))

	<modules runAllManagedModulesForAllRequests="true">

        <rewriteMap name="StaticRedirects">
<!-- this is similar to url mapping, but the user would actually see the aspx extension in the url -->
          <!-- <add key="/subsitefoldername/pagename" value="/pagename.aspx"/> -->
        <rule name="RedirectRule" stopProcessing="true">
          <match url=".*" />
            <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
          <action type="Redirect" url="{C:1}" appendQueryString="True" redirectType="Permanent" />
          <rule name="default">
            <match url="default" />
            <action type="Rewrite" url="default.aspx" /> <!-- this hides the extension as intended -->
        <rule name="login">
          <match url="login" />
          <action type="Rewrite" url="login.aspx" />

Unfortunately however, the above example can break page validation/viewstate, but that’s a topic for another article. :P

There is one other alternative to note that I also tried which also worked on my local server but not on GoDaddy was using Global.asax context rewrite. To avoid lengthiness, see deferred post on URL Rewriting/Mapping using Global.asax.

“Simple URL Rewriting/Mapping in IIS7″,
Learn IIS,,,
Godaddy kbase,

Simple URL ReWriting/Mapping in IIS7

There’s an easy alternative to other over-complicated solutions on the web if your mappings are simple/static and/or you have a spare grunt to quickly and easily keep them updated without having to write a line of code.

In web.config add:

    <modules runAllManagedModulesForAllRequests="true" />

Under system.web add static mappings like so:

<urlMappings enabled="true">
			<add url="~/default" mappedUrl="index.aspx"/>
			<add url="~/login" mappedUrl="login.aspx"/>
			<add url="~/logout" mappedUrl="logout.aspx"/>


Of course some scenarios require more complex mappings, but for most non-ecomm/non-web app sites and even blogs this solution would work np, be faster to maintain without requiring assembly publishes and is less error-prone.


If you are unfamiliar with the term; PHP is a very popular open source web development language.

It runs server side like ASP.Net instead of client side like javascript, and has many of the same features also seen with .Net.

Usage wise, it is arguable by many which language is “superior”, but they both have their pros and cons. After using both extensively, I would have to say I am more preferable to .Net, but PHP still has it’s uses.

One major disadvantage though in my opinion, is having to require separate servers or services to utilize both. Although Apache web server is very popular, and the usual choice for delivering PHP content, it is much easier to configure IIS for a windows or .Net developer or admin, and streamlines the process a little more.

I was a little skeptical of using PHP on IIS6, however, I can trustfully say IIS7 is a good alternative to apache for your PHP applications, and would recommend it to anyone migrating from a windows environment or with developer staff that is cross-platform.

See references below for link to install and configure including a nice PHP Manager which plugs right in to your IIS management interface.

IIS.Net, “PHP on IIS7″,, “PHP Manager for IIS”,
Wikipedia, “PHP”,

IIS 7 Remote Administration Manager

At the time of writing this article, in the latest version of Windows (Vista,7 and Server 2008), IIS management has changed quite a bit.

IIS7 features some very cool remote management capabilities. In an environment where developers may need access to IIS, but not necessarily the server, or too many remote logins to the server fill up the TS licenses, using IIS remote management can save ALOT of your time and money.

Consider the following scenarios:

New site needs to be added to IIS or changes to existing site need to be made.

1) Developer does not have RDP access due to corporate security policies or may be outside consultant, etc and submits ticket/request for new site to be added
2) Count the time delay until ticket is responded, time to form responses and time spent on actual technical changes.
3) If details regarding site changes sent by developer are adequate, IT helpdesk applies the changes and notifies developer setup successful. If additional info is needed, helpdesk must request more information, then repeat steps 2-3 until complete.

Even if only 1% of all sites require follow up, and approximate ticket response and IIS configuration time is lets say 3-4 hours including delay until ticket is received; if you create 50 sites / annually this equates to 150-200 hours spent simply on site setup.

If your company outsources IT helpdesk, or response time is even slower, 12-24 hours, this is now 600-1200 hours of delay at the same rate of 50 sites / annually.

To save time (and money), consider cross-training developers that don’t know IIS, and setup remote administration in IIS7.

Note some Vista and Windows 7 installations do not come with the manager, and it will have to be downloaded from

For walkthroughs on this configuration and more information, see references below.

TrainSignalTraining, “Remote Administration of IIS 7: Install, Configure, Connect”,
IIS.Net, “IIS Manager for Remote Administration”,


Get every new post delivered to your Inbox.