Showing posts with label MVC 4. Show all posts
Showing posts with label MVC 4. Show all posts

Wednesday, May 1, 2013

New project for the belgian market

Edit: To comply with the laws of Belgium, the site has been put offline (some exchanges were not legal and I do not want to be responsible of that).

Last week, I launched a new site dedicated to the Belgian market (and maybe I will be targeting other countries after...): ChequeChange


The site is prety simple and is dedicated to the exchange of meal/eco vouchers in Belgium: this is not a business that fascinates me but making this project will be useful for some people and has help me to improve my skills! (the code and the databases of my next projects will be better!)

The website has been realised with the following technologies:

- ASP.NET MVC 4
- Entity Framework 5.x (but I still prefer using stored procedures that EF can map...)
- Windows Azure (2 small instances for the moment)
- MetricsHub (for monitoring and in case of automatic scale out needed... very good product!)
- SQL Azure
- Azure Storage
- Azure CDN
- Azure AppFabric Caching (thanks to MVC Donut Caching...)

The design is -almost- responsive and the site can be used on all the devices ;-)

This is my second experience with Windows Azure... I like this product! The SDK is excellent and up to date, the portal is well done and easy to use, the analytics are useful, performance are good, etc. A great product!

Thursday, February 28, 2013

Chronic: "Programming ASP.NET MVC 4"

I recently read a new book: Programming ASP.NET MVC 4. This interesting book has been written by Jess Chadwick, Todd Snyder and Hrusikesh Panda and is about the latest ASP.NET MVC version (4).


Here is the list of the topics (by chapter) covered in this book:
  1. Fundamentals of ASP.NET MVC: The MVC Architecture, New in ASP.NET MVC 4, ...
  2. ASP.NET MVC for Web Forms Developers: More Differences than Similarities, ...
  3. Working with Data: Building a Form, Validating Data, ...
  4. Client-Side Development: Working with JavaScript, AJAX, Client-Side Validation, ...
  5. Web Application Architecture: Architecting a Web Application, Design Principles, ...
  6. Enhancing Your Site with AJAX: Partial Rendering, Sending Data to the Server, ...
  7. The ASP.NET Web API: Building a Data Service, Exception Handling, ...
  8. Advanced Data: Data Access Patterns, Building a Data Access Layer, ...
  9. Security: Building Secure Web Applications, Guarding Against Attacks, ...
  10. Mobile Web Development: Application Mobile Friendly, Adaptive Rendering, ...
  11. Parallel, Asynchronous, and Real-Time Data Operations: Asynchronous Controllers, ...
  12. Caching: Types of Caching, Server-Side Caching Techniques, Client-Side Caching Techniques, ...
  13. Client-Side Optimization Techniques: Anatomy of a Page, Best Practices, Measuring Client-Side Performance, ...
  14. Advanced Routing: URLs and SEO, Building Routes, Route Constraints, ...
  15. Reusable UI Components: What ASP.NET MVC Offers out of the Box, Unit Testing Razor Views, ...
  16. Logging: Error Handling in ASP.NET MVC, Logging and Tracing, ...
  17. Automated Testing: Levels of Automated Testing, What Is an Automated Test Project, Testing an ASP.NET MVC Application, ...
  18. Build Automation: Creating Build Scripts, Automating the Build, Continuous Integration, ...
  19. Deployment: What Needs to Be Deployed, Deploying to Internet Information Server, Deploying to Windows Azure, ...
And some appendixes: ASP.NET MVC and Web Forms Integration, Leveraging NuGet as a Platform, Appendix Best Practices, etc.

I enjoyed reading this book: as the title says, it's really about the Real World Web Applications. My knowledge of ASP.NET MVC was already advanced, but I had to rethink my expertise in architecture development, consider tight coupling of classes, etc.
I recommend this big book (500 pages...) to people who already know the basics of  ASP.NET MVC or to the ASP.NET Webform developers.

I will soon receive another book: Exploring CQRS and Event Sourcing: A journey into high scalability, availability, and maintainability with Windows Azure. Perhaps another small chronic to come ;-)

Tuesday, November 6, 2012

Tips for ASP.NET MVC 4: lowercase URLs

A small article about a new feature in ASP.NET MVC 4: the new LowercaseUrls property... (not exactly a new feature of ASP.NET MVC 4: the routing is a part of the .NET Framework itself. The LowercaseUrls property is available in all the projects which use .NET 4.5, whether it’s ASP.NET MVC 3 or ASP.NET MVC 4...)

The problem with ASP.NET MVC is that URLs generated thanks to the routing mechanism are based on the controller and action names. These will typically be resulting in URLs like /Account/Login, etc.
But the routing mechanism is not case-sensitive and a request to account/login works just the same.
It's not a good practice for the SEO to allow URLs with any casing because it could technically be considered to be duplicate pages with the same content.

Usage is very simple, just set the property like in the following code:

   1:  public static void RegisterRoutes(RouteCollection routes)
   2:  {
   3:      ...
   4:      routes.LowercaseUrls = true;
   5:      ...
   6:  }

You can test the modification with a simple action link:

   1:  @Html.ActionLink("Home", "Index", "Home")

An you will see this result:

   1:  <a href="/home/index">Home</a>

You don't have to worry about the capital letters in your URLs but this is not a reason to forget some good SEO practices: you can see some tips here.

Saturday, October 27, 2012

Donut Caching with ASP.NET MVC 4

I'm working on a new personal project during my free time and I chose to develop it with ASP.NET MVC 4 (hosted on Azure of course...) to test the new features of this version.

In this project, I need to display "Logged in as xxxx " (if the user is logged...) in the header of the page. This is a simple scenario to implement but caching could complicate the development of my web app...

My header is in my layout and is used everywhere but I would like to place an OutputCacheAttribute on some actions (the home page, etc.). If I put the attribute on an action, all of my users will see an header with "logged in as xxxx" of the first incoming query!

The solution to this problem is named "Donut Caching": you send a cached page from the server with a "fresh" portion which is not in cache (the donut's hole).
Concretely, the server does not generate the requested page (query the DB, etc.): it just needs to take the cached version and replace a specific part.

Luckily, you do not need to develop your own custom OutputCacheAttribute because there is already a very good package (There's An App A Pack For That... thanks NuGet!): MvcDonutCaching for ASP.NET MVC 3 and later...

To install the package, you can search through NuGet or directly type the following command in the "Package Manager Console":

   1:  install-package MvcDonutCaching


The use of this package is very simple... They have created several extension methods for HtmlHelper with the usual parameters plus another boolean parameter: excludeFromParentCache. I just have to call my partial view (with the "connected has xxxx"...) like that:


   1:  ...
   2:   
   3:  @Html.Action("LoginHeader", "Account", new { lang }, true)
   4:   
   5:  ...

The last parameter of Html.Action is set to true: this partial view will be excluded from the parent cache (if there is a cache on the action...). (do not pay attention to new { lang }, it's a route's value)

To make it work, you must not use the OutputCacheAttribute but the DonutOutputCacheAttribute:


   1:  [DonutOutputCache(Duration = 60, VaryByParam = "lang")]
   2:  public ActionResult Index(string lang)
   3:  {
   4:      ...
   5:   
   6:      return View();
   7:  }

And that's it! The first request will be cached during 60 seconds but the LoginHeader partial view will be generated every time.

(note: of course, the donut caching only works on the server side...)