Wednesday, February 29, 2012

Debugging ASP.NET MVC in IIS

Some notes:

  • Add IUSR and IIS_IUSRS for read access to project folder.
  • Setup a virtual directory in IIS pointed to project folder.
  • Change project settings to use Local IIS web server at same URL as mapped virtual directory.
  • Clean & Rebuild solution.
  • If connecting to database using integrated security, switch app pool identity to current user (Advanced Settings -> Identity).
  • Optional: open up firewall for accessing site from other systems.
  • If publishing from Visual Studio, make sure all images/css/scripts are included in the project so that they will be deployed.

Dropbox + Google Apps Engine + Google Apps = Free Web Hosting

Each Dropbox account has a Public folder with a fixed base URL from which one can make files publically available on the web. Any file can be served, including static HTML files. So why not use Dropbox to host a simple website? I'll tell you why: because the base URL is a sloppy mess which makes straight domain forwarding impossible.

This dude has a pretty cool workaround--use Google App Engine to host a URL-rewriting service specially configured to proxy requests from the app to Dropbox. He calls it DropbProx (a specific version of the more complete mirror proxy, mirrorrr). And since the GAE application gets a sweet URL in the form appname.appspot.com, it's ripe for domain forwarding.

In order to transfer the application files to your GAE account, you'll need to install the Google App Engine SDK. If you're a Windows user, I suggest the SDK for Python--which requires, of course, the Python runtime.  Here is a straight-forward tutorial (pics and vid included) on installing the SDK and deploying an application to GAE.

Once the app is up and running and forwarding requests from your app URL to your Dropbox URL, go to the GAE dashboard under Administration >> Application Settings >> Domain Setup. From here, you can "host" your application under your Google Apps domain.

Now head over to the Google Apps dashboard, and under Settings, your app should be listed in the Services column as "your-app-id (App Engine)". Follow the steps to map the www subdomain to your-app-id.appspot.com. The final step will be access your domain name provider and add a CNAME record to your DNS settings that will map www to ghs.google.com. For bonus points, have your DNS provider map your naked domain to the www subdomain so that yourdomain.com and www.yourdomain.com both send users to your website.

A final caveat: the Dropbox public folder is not an actual web server. So it won't assume a call to an open-ended URL will default to index.html, index.htm, index.php, etc. That logic would have to built into the proxy application. Still, not too shabby for free web hosting.

Tuesday, February 28, 2012

Confusing Week of Month with Nth Weekday of Month

Protip: Don't confuse computing the week of the month during which a day occurs with computing which Nth weekday of the month a day occurs (day/7 + 1 where day is the day of the month from 0-30).

Thursday, February 23, 2012

HostingEnvironment, Where Have You Been All My Life?

Son of a bitch!

Here'd I'd been schlepping around instances of the HttpContext in my MVC app so that I could use Server.MapPath() -- when all this time I could have been using the static method System.Web.Hosting.HostingEnvironment.MapPath().

Learn something new every day, I guess.

Tuesday, February 21, 2012

Tortoise SVN Sparse Directories

So I had checked out this project from SVN and with it came a dozen or so release branches I wasn't going to need. Now since these release branches were subfolders of the main project, they didn't have individual .svn folders to delete. Thus Tortoise SVN exporting wouldn't work either.  And just deleting the folders outright meant I was only one thoughtless commit away from removing them from the repository all together.

I needed some way to remove them from my local system without indicating to Tortoise SVN that I wanted to delete them from source control.  Enter the sparse directory update (src1, src2, src3).

From the Tortoise SVN context menu for a given folder, select "Update to revision". Set "Update Depth" to "Exclude", and use "Choose items" to select the folders you want to keep. Verify "Make depth sticky" is selected so you won't have to repeat this process after every code update. After a minute or two of SVN doing its thing, you'll have all of the folders you want and none that you don't.

Friday, February 10, 2012

jQuery Plugins (Non-jQuery UI Version)

I was (and still am) a fan of the jQuery UI widget template system (src1, src2, lmgtfy) for creating modular UI functionality. But if you're not a fan of the overhead of including the jQuery UI libraries, you can create the same effect with just plain 'ol jQuery plugins. You don't get all the bells and whistles of the widget factory, but as you can see, the set up is still very straightforward.

(function ($) {

    var settings = {
        // ...
    };

    function _private(options) {
    }

    var methods = { //public methods
        init: function (options) {
            $.extend(settings, options || {});
            return this..each(function () {
                // ...
                // use settings
                // ...
                // call _private
                // ...
            });
        },
        destroy: function () {
            // ...
            // unbind events, remove DOM objects, etc
            // ...
        },
        f1: function (args) {
            // ...
        },
        // ...
        fN: function (args) {
            // ...
        }
    };

    $.fn.pluginName = function (optionsOrMethod) {
        if (methods[optionsOrMethod]) {
            return methods[optionsOrMethod].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof optionsOrMethod === 'object' || !optionsOrMethod) {
            return _init.apply(this, arguments);
        } else {
            $.error('Method [' + optionsOrMethod + '] does not exist');
        }
    };

})(jQuery);