Using .less{} (dotless) with MVC4 Web Optimization

I have been searching long and hard for how to find a way to preserve most of the Web.Optimization capabilities in MVC4 when using less to build my CSS.  I found a post by Ben Cull that got me MOST of the way.  Essentially there are a few easy steps that you need to take in order to enable this.  The primary change that I made was to turn on minification if I was running in DEBUG mode vs RELEASE.\

Steps to get less transforms working with Web Optimization...

  1. Install the BundleTransformer.less package from nuget.
    1. Using this... "Install-Package BundleTransformer.Less" in the Package Manager Console
    2. Once this installs it will pop-up a new open file with some modifications that you need to make to the web.config of your project.
  2. The rest is in code and I'll post below.  Some of this is from Ben Cull and some is the modifications that I have made...  I'm only including my less bundle which is what I have modified.  All the other bundling techniques work just fine in my situation.

 

public static void RegisterBundles(BundleCollection bundles)
     {

            BundleTable.EnableOptimizations = true; //Comment or un-comment this line to force bundling/minification in a project so you can see how it will behave at release.

            var cssTrans = new CssTransformer();

            var cssMin = new CssMinify();

            var nullOrdered = new NullOrderer();


            var siteLess = new StyleBundle("~/Content/less/siteLess").Include(

                "~/Content/less/bootstrap.less",

                "~/Content/less/responsive.less",

                "~/Content/less/site.less");

            siteLess.Transforms.Add(cssTrans);

#if !DEBUG

            siteLess.Transforms.Add(cssMin);

#endif

            siteLess.Orderer = nullOrdered;

            bundles.Add(siteLess);
     }

I have removed all the non relevant bundles that I have enabled on the site I'm working on.  Simply retain what you have add the transform variables at the start of your method and you should be good to go!

SimpleMembership Provider Oauth Issues (and fix)

I've been experimenting with the MVC4 template to possibly rebuild a site I had recently started.  The sites that I build are all on a shared hosting provider (Arvixe).  One of the issues that I had is that when you create a database on Arvixe it sets the table schema to whoever the owner is.

SimpleMembership expects a dbo schema name.  This turned out to be a simple fix luckily and something that I just happened to find myself and couldn't seem to find anywhere else.  The other issue that I had is that the only time this issue ever showed itself is when I enabled Oath and tried to log in with one of the providers.  The only thing that it shows on a deployed site (for me at least) was a HTTP 500 error.

The fix.... In ~/Models/AccountModels.cs

[Table("UserProfile", Schema = "YourSchemaNameHere")] 
public class UserProfile { 
    [Key] 
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 
    public int UserId { get; set; } 
    public string UserName { get; set; } 
}

The above is the Object definition for a UserProfile and come into play anytime tries to connect through Oauth.  The default Table annotation for the class ONLY contains the [Table("UserProfile")] to correct it you have to access the overload on the annotation and pass in the Schema parameter.

Hosting Review - Arvixe

I recently switched to Arvixe from GoDaddy (and haven't looked back).  

I made the switch for a couple of reasons.

  1. GoDaddy was a supporter of SOPA
    1. They now have switched their stance to no longer supporting SOPA, but this was simply a business move...  I don't want to support a company that if given the opportunity would support something like SOPA
  2. GoDaddy isn't a full-trust provider
    1. This made it so that I couldn't even use the MySQL EntityFramework Library
  3. GoDaddy has a HORRIBLY limiting policy on database count and size
Arvixe on the other hand has several selling points that I have really enjoyed.
  1. Unlimited Space/Bandwidth/Databases/Email/etc
    1. (Databases do have an individual 10GB limit)
  2. 6 Domains are hosted on their Personal Class ASP hosting.  Step up to the PRO and you get unlimited ($3 extra month).
    1. On either plan you can have an unlimited number of subdomains
  3. They now support .NET 4.5!
  4. If you need SSL it's only $24/yr ($2/mo) for a dedicated IP for a given domain.
    1. Admittedly an actual SSL Cert is something that I will still buy from GoDaddy simply because they can be had for $17 (I believe) a year.
  5. On ALL their plans they offer a free .COM for life... So as long as you maintain hosting they will pay your yearly renewal.  They also sell a domain at a flat $10 which is cheaper then GoDaddy's renewal rates.
The (possible) "bad"
  • Arvixe's control panel isn't what GoDaddy's was, but I have yet to find anything that I can't do through it.  Just doesn't seem quite as streamlined.
  • It does "seem" that the traffic speed is slightly slower on Arvixe, but I have never done any benchmarking to compare the two so this may just be a perception thing.
    • It is still plenty fast and is still acceptable given the other benefits.
  • They are a full-trust provider.  For me this is a HUGE benefit.  However, it does open the server up to some possible issues, but at the moment I've NEVER had any issues because of this and the benefits FAR outweigh the POSSIBLE issues.
If you are looking for a host give them a shot.  They offer a 60-day money back offer when signing up.  If possible please use the links on the site vs typing into the address bar.  They have an Affiliate program that I'm part of and it's part of how I pay to keep the site up.

About the author

Something about the author

Month List

Page List