Tag Archives: .NET

KendoUI Grid, OData, WebAPI and Entity Framework

In the latest project I was involved with, there was a need to present database tables data directly in the Umbraco’s backoffice, where all CRUD operations must be supported. This tables could be something like 1000 to 1 million rows and both the website and database would be hosted in Azure, in a WebApp and SQL Database respectively. Users should be able to create complex filters and order the data as they wish as well as update the data individually and in batch.

From the get-go there were some challenges we needed to overcome in order to create an usable system, that was user-friendly, fast, reliable, and where no conflitcts would come up when data was being updated from multiple users.

The solution was a new Umbraco Package we called Search Manager (since the database tables ultimately feed an Azure Search index) that uses Telerik’s Kendo UI Grid, WebAPI and Entity Framework. The following presents the process it took to reach the end result.

Continue reading

Umbraco and Donut Output Cache

Donut Output Caching is a type of output caching where certain parts of a web page are not cached. It’s a simple way of boosting your site performance!

ASP.NET doesn’t provide a native way of donut output caching, so we must resort to a great NuGet package called MVCDonutCaching. You can read all about it here: http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3.

Since Umbraco is built on top of ASP.NET MVC, we can easily use this package on our websites. There are, however, some caveats, because Umbraco doesn’t use the native MVC routing.

For Umbraco, every page that uses the same document type is processed through the same route, therefore, if we have 100 news articles that use the NewsItem document type, from the moment we open one news article page, every other news item page will display the same information, despite having a different URL!

Continue reading

Umbraco profiler

Quick tip:

If you need to find which part of your Umbraco application is slowing the site down, follow these steps:

  1. Set the debug property of the compilation section of your Web.config to true<compilation defaultLanguage=”c#” debug=”true” batch=”false” targetFramework=”4.5″>
    • If you’re using an older version of Umbraco, you also probably need to set the umbracoDebugMode app setting to true in the same config file: <add key=”umbracoDebugMode” value=”true” />
  2. Add the query string ?umbdebug=true to your Umbraco page URL
  3. Thats it!
umbraco profiler
umbraco profiler

It uses Mini Profiler, so you can add your own profile stops, but out-of-the-box it already analyses the time it takes to render each view.

Happy profiling!

Remote resource handling in a MVC website project

I don’t have very fond memories of using .Net resource files (.resx) to handle the translation of static web page elements such as form labels.

The Visual Studio resx editor was slow and using it to change resources that were more than a single line of text was a pain. I still have nightmares where I’m trying to edit complete email templates on a single field of a resx file…

The biggest problem with resource files, however, is that they are included in the project. This creates a problem for both the developers and the content managers, since the content managers are not able to change resources themselves, and the developers need to be changing resources files when they could be doing something productive.

The following will show a way to handle resource items in a MVC website project, where the resources can be stored wherever they are more easily handled by content managers: a SharePoint list, a database table, an excel file, or something completely different.

Continue reading

Building an Umbraco 7 backoffice extension – Part III

The previous post (Part II) showed how to populate the content tree of a custom Umbraco backoffice section. This one presents a way for content managers to quickly handle each post pending approval, which means we’re going to create our own AngularJS controller and view.

AngularJS is a MVC javascript framework mainly mantained by Google which primary goal is to aid in the development of single-page applications. It’s use on the Umbraco backoffice was the most notable change when Umbraco 7 was first released.

When the content manager selects one node pending approval we want him to be able to take three quick actions:

  • get some information about that node;
  • quickly access it in the content section;
  • quickly publish it.

Continue reading

Building an Umbraco 7 backoffice extension – Part II

The previous post (Building an Umbraco 7 backoffice extension – Part I), demonstrated how easy it is to create a new section in Umbraco’s backoffice. This post will show how we can populate this new section with meaningful content coming directly from the backoffice.

To begin with, we must reference a few more assemblies (also available at the Umbraco’s installation bin directory):

  • umbraco.dll
  • cms.dll
  • Umbraco.Core.dll
  • System.Web.Http
  • System.Net.Http.Formatting

Then we can populate our section with a tree containing content awaiting approval. To accomplish this we must extend an Umbraco class named TreeController and decorate it with information about our Approve It plugin:

Continue reading

Building an Umbraco 7 backoffice extension – Part I

Umbraco is a lean and powerful  CMS built on top of current .NET technologies and Javascript frameworks. It provides developers with a varied and simple to use collection of APIs, it is easy to customize and doesn’t get in the way between the coded markup and the HTML that is actually rendered.

The next series of posts will show how to build plugins that extend the default Umbraco backoffice capabilities.

Continue reading

Azure CDN, BlobStorage and ImageResizer

In a recent project, we had the need to serve website assets and website content images through a CDN network. Furthermore, each image presented in the website content must be available in multiple resolutions.

We ended up serving both the assets and content images through the same Microsoft Azure CDN. This post describes the way we implemented it.

First the easiest part. We have our site in a Azure Website, in order to serve the site’s assets through an Azure CDN we only needed to point the CDN to the website’s URL. So, if the website’s assets are located in something like http://sitedomain/assets/*, instead of referencing the assets through a relative url such as /assets/*, we just need to use the CDN url to serve them: http://cdnurl/assets/*. Through web.config transforms we are also able to use local assets during development and change to CDN only on the production environment.

Regarding the website image content, the solution has three phases.

Continue reading

A Multi-Tenant Website in MVC

In my most recent project we had the need to build multiple websites that would share some common functionalities but would be installed in separate servers and would be available in different domains.

We were using .NET 4.5 and MVC 5 and there was no out of the box solution for this problem. Throughout my search I came upon this paper and we took some ideas from it. This post describes the main changes to a normal website project we had to make in order to make this work.

Continue reading

Pre-set common viewmodel properties before action result

So, I defined a master model that is shared by every view in my MVC site. This model defines a bunch of properties that are always used on every page, such as a page title, page description, the google tag manager code, etc.

I need this model to be filled before the action result, so that I can use those properties on the view.

In order to do this, I created a custom Action Filter Attribute that is used by every action:


    public class SetupMasterModelActionFilter : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ViewResultBase result = filterContext.Result as ViewResultBase;
            if (result == null)
            {
                return;
            }

            MasterModel model = result.Model as MasterModel;
            if (model == null)
            {
                return;
            }

            SetupMasterModel(model);
            SetupViewBag(result, model);
        }

        private void SetupMasterModel(MasterModel model)
        {
            ...
        }

        private void SetupViewBag(ViewResultBase result, MasterModel model)
        {
            ...
        }
   }

Continue reading