Thursday, July 5, 2012

Get dotlesscss to show compile errors

If the compile of a .less file fails with dotlesscss it will often just show a blank page. To make it show the compile error, just add a logger to the config (see answer by tony722).

This settings worked for me:


<dotless minifyCss="false" cache="false" web="false" logger="dotless.Core.Loggers.AspResponseLogger" />

See list of options here.

Friday, June 29, 2012

.less files gives 404 or 406 error on IIS

A quick reminder to myself if I ever run into this problem:  When using .less as css it might work fine when running thru Visual Studio but it fails with a 404 or a 406 when deploying to the IIS server. (ie. the CSS is not applied to the web page).

Probable solutions are here (404 - need to specify mime type) and here (406 - need to have consistent types).

Also should have IIS in Integrated Mode, not Classic if possible. Found this tip here

Monday, June 11, 2012

Problems installing ASP.NET MVC3

I recently installed the CMS Umbraco 5, but I had problems getting it to run because I didn't have MVC3 installed. When I used Web Platform Installer to install it - it didn't work (I think there was no error message even) - after installing MVC3 the files where nowhere to be found.

The error you'll receive is (when running Umbraco): Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

The reason MVC3 won't install is because I had a newer version of NuGet installed (v1.5). The installer produces a fatal error when it finds a newer (than 1.2) version instead of continuing. The semi-official fix from Microsoft is to uninstall Nuget, install MVC then reinstall Nuget.

There is also another workaround, to manually run the installation files after the installer has extracted them (start installation, when it fails find the extracted installation files in the Temp folder and copy them somewhere else. Then install them manually after finishing the first install).

Note that the problem is actually in the 'MVC3 Tools' package, so for me it worked to simply install the binaries (since I'm just going to run Umbraco, not develop MVC3 apps I don't need the tools).

Download just the runtime from here: http://www.microsoft.com/en-us/download/details.aspx?id=4211

The tools are here (in case you need them): http://www.microsoft.com/en-us/download/details.aspx?id=1491

Tuesday, June 5, 2012

ASP.NET MVC 4 and mobile web

Here is how to set up for mobile web on MVC 4 (or at least my preferred way) follow instructions here:

Note the comment from Chip below the article, there is a Last-In-First-Out principle for the order of specifying the order of devices. So instead of the order used in the article, use Chip's.

Also note that the examples are for MVC 4 developer preview, the correct way in MVC 4 beta is 
  • DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("mobile")
instead of
  • DisplayModes.Modes.Insert(0, new DefaultDisplayMode("mobile")


So updating and combining the info, this is the correct way in global.asax:



DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("mobile") {
          ContextCondition = Context => Context.Request.Browser.IsMobileDevice
});


DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Tablet"){
          ContextCondition = Context => [how to id tablet]

});

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("AndroidTablet"){
         ContextCondition = Context => [how to id android tablet]

});


)

jQuery Mobile stuff

I just started using jQuery Mobile and ran into a few gotchas. First is that when going from one page to another what actually happens is that jQuery Mobile does some Ajax magic in the background. This means that the second page is not loaded in the traditional way.

I got hit with this when my third page in a sequence was supposed to load a javascript file, i did this in the header but since it was ajax, the header referencing the script file wasn't actually loaded - same with document.ready(). It was a little head scratching before consulting the docs where it is actually written clear:

Important: Use $(document).bind('pageinit'), not $(document).ready()


Same with referenced javascript files, they have to be referenced in the page contents not the header.

Second after showing some html I got through my own ajax service in a dialog, the next time it showed it would be without styling. jQuery Mobile only styles elements once, so second time the dialog was shown jQuery Mobile assumed that it already had styled the html in it. To force a restyling do like this:

            $.ajax({
                url: urltosomeajaxservice,
                type: 'POST',
                data: form_data,
                success: function (data) {
                    $('#streets').html(data);
                    $.mobile.changePage('#mydialogpage'truetrue);
                    $('#mydiv').trigger("create");
                },
                error: function () {
                    //alert("Error!");
                }
 
            });


 Note the .trigger("create") - which does the restyling. The markup:

<div data-role="dialog" id="mydialogpage">
    <div data-role="content" data-theme="b">
        <div id="mydiv">
        </div>
    </div>
</div>

Friday, May 25, 2012

Could not load type 'System.Web.WebPages.DisplayModes' from assembly 'System.Web.WebPages, Version=2.0.0.0

I got this annoying error recently on my ASP.NET MVC 4 Beta project and didn't find any real solutions/explanations on Google. So after investigating it here are my findings.

The basic problem is that there is a mixup between MVC 4 Developer Preview and MVC 4 Beta .dlls in the project. To see which version you have right click the .dll file in Windows Explorer and choose Properties->Details. Look for  'File Version' :

  • MVC 4 Developer Preview is version 4.0.10906.0
  • MVC 4 Beta is version 4.0.20126.16343


Make sure all says the MVC 4 beta version number (replace the .dlls from a fresh MVC 4 Beta project if necessary) for these files:

  • System.Web.Mvc
  • System.Web.WebPages
  • System.Web.Razor
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor

It should then work.

(Technical: It is actually the older version of System.Web.Mvc.dll that tries to use a removed/changed item in the newer System.Dll.WebPages library. DisplayMode have been replaced with DisplayModeProvider)

Tuesday, May 22, 2012

Fake a mobile device with Chrome

To make Chrome identify as another browser see the comment from Alexander Pavlov here:

http://stackoverflow.com/questions/7561271/user-agent-switcher-for-chrome

I'll repeat it: Open developer tools (Ctrl+Shift+J or Ctrl+Shift+I) and click the small gear icon bottom right to open settings. Check 'Override User Agent' and select the one you want.

This is very useful for testing mobile web pages as you can use chrome to test instead of on a physical device.

Note: This only works as long as you have the developer tools window open, and only in the tab you opened them in.

Column number in Excel

To find the column number (instead of letters) use the Column() command. Eg. for columnt 'AE' write in any cell:

=Column(AE1)

The cell then displays 31 which is the numeric column index (starting at 1). The '1' is after AE specifies the row, doesn't matter wich one you specify so seems quite pointless - but it needs to be there.