Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
DZone MVB

Links

Social

March 2012 - Posts

ASP.NET MVC 4: Short syntax for script and style bundling

ASP.NET MVC 4 introduces new methods for style and scripts bundling. I found something brilliant there I want to introduce you. In this posting I will show you how easy it is to include whole folder with stylesheets or JavaScripts to your page.

I’m using ASP.NET MVC 4 Internet Site template for this example. When we open layout pages located in shared views folder we can see something like this in layout file header:


<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
  

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/themes/base/css")" rel="stylesheet" type="text/css" />
  

<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script>


Let’s take the last line and modify it so it looks like this:


<script src="/Scripts/js"></script>


After saving the layout page let’s run browser and see what is coming in over network.

ASP.NET MVC 4: Request to scripts folder is legal

As you can see the request to folder ended up with result code 200 which means that request was successful. 327.2KB was received and it is not mark-up size for error page or directory index. Here is the body of response:

ASP.NET MVC 4: Request to script folder ends with bundled script

I scrolled down to point where one script ends and another one starts when I made the screenshot above. All scripts delivered with ASP.NET MVC project templates start with this green note. So now we can be sure that the request to scripts folder ended up with bundled script and not with something else.

Conclusion

Script and styles bundling uses currently by default long syntax where bundling is done through Bundling class. We can still avoid those long lines and use extremely short syntax for script and styles bundling – we just write usual script or link tag and give folder URL as source. ASP.NET MVC 4 is smart enough to combine styles or scripts when request like this comes in.

Windows 8 Metro development–are they serious?

When Windows 8 Consumer Preview came out I downloaded it same day and installed on virtual machine. Of course, I also installed new Visual Studio 11 beta on it. Then I started playing with metro applications and I am very confused and a little bit disappointed about how broken and limited everything will be on WinRT right now. Here are some of my thoughts.

Metro apps are extremely buggy

Over years I have seen no such a pile of bugs in Microsoft product that should be Release Candidate (RC). Windows 7 beta and RC were brilliant. They worked like charm and after couple of weeks with beta I started using it as my main operating system. Okay, there were some small crashed and BSOD-s but still it was extremely stable.

Now Windows 8 is different. Everything else seems to work almost normally but when we start with Metro then everything falls down. Some of my findings are here:

  1. Suddenly with reason I was not able to identify videos doesn’t play normally in Metro applications. Audio stream is played normally but picture is black. If I run Windows Media Player – this is usual Windows application – on same machine and try to watch videos then everything works fine.
  2. Problem with video playback exists also on IE10. It doesn’t matter if I run it from desktop or from new start screen. It worked before for some days and then problems started. By the way – Build application fails exactly same way.
  3. Couple of days more and IE10 doesn’t open from new start screen anymore. It opens for a moment and then shuts down. Best it can do is to stay open and show blue starting screen but nothing more.
  4. Other Metro apps almost like work. Sometimes they crash, sometimes they are extremely slow and doesn’t react to new mouse gestures. My virtual machine has enough resources to run Windows 8 normally.

I have no good idea what is going on behind curtains or why Microsoft released so buggy version of Windows 8 but considering that they have time about four months to develop + one month to test and debug Windows 8, I am not very sure how bright will be its launch. I mean third-parties need also time to build their apps and test them on stable versions. Thinking this way I am not very sure how competition with Apple iPads will look like or what will be the result.

WinRT API-s: Another bad surprise

Now, let’s go and try to build something useful for my business. Let’s build Metro application that communicates with web services. Is it possible to make something work that uses web services built on previous versions of ASP.NET? Is it possible to use NTLM? Is it possible to use SSL with basic authentication? No, guys, forget it for now. Here are some of my really bad findings:

  1. Support for ASP.NET web services is completely broken if you need some more advanced features like authentication.
  2. NTLM authentication doesn’t work. What is more annoying is one blog post I read where one of Microsoft dudes told about Windows authentication in Metro something like this: we don’t plan to support it but if people ask then there will be some support for Windows authentication. Okay, guys, you just made head shot to SharePoint, Office 365 and Dynamix CRM.
  3. I reconfigured my web services so they use basic authentication. And guess what – again same errors about how communication on socket level fails. When I enabled anonymous access to web services then suddenly I was able to communicate with them. And with me, of course, the whole world.
  4. There is no way to reference libraries built on working versions of .NET. If you have libraries that do something useful then you have to create special Metro version of them. So you end up with two parallel code-bases that do exactly the same thing. Yes, you are just human being and therefore the worst machine to handle duplications but this is the way how you must live with your Metro applications right now.

I’m not very sure why Windows 8 and Metro development is such a bad mess. I don’t know why it is impossible to build secure business applications on Metro. I really hope that Microsoft is in hurry with many developments on Windows 8 and Consumer Preview was just one unhappy nightly build that was pushed to market. If things are not going way better for a time when stable version is made public then first and most important battle for market is lost for Microsoft.

Posted: Mar 11 2012, 10:27 PM by DigiMortal | with 14 comment(s) |
Filed under: ,
More Posts