Azure | .Net | JQuery | Javascript | Umbraco

Umbraco Life Savers


The model item passed into the dictionary is of type ‘Umbraco.Web.Models.PartialViewMacroModel’, but this dictionary requires a model item of type ‘CWSStart.Web.Models.LoginViewModel’.


The issue was that another member of my team had created a Banner.cshtml file in /Views/MacroPartials and this Partial View was being loaded instead of my one.

My case:

i had a view with the same name on the AuthSurface folder and in the views folder.


Leave a comment »


Services that make up the IIS 7 Web server include:


Display Name



Default Startup


Application Host Helper Service

Stores configuration history and application pool mapping in history subdirectories at set intervals.




FTP Publishing Service

Enables IIS 7 Web servers to be File Transfer Protocol (FTP) servers.




IIS Admin Service

For IIS 6.0 metabase configuration compatibility




FTP Publishing Service 6

Enables IIS 6 Web servers to be File Transfer Protocol (FTP) servers.




World Wide Web Publishing Service

Provides Web connectivity and administration through IIS Manager




Windows Process Activation Service

Provides process activation, resource and health management services for message-activated applications.




Web Management Service

Enables remote management of a Web server.



To troubleshoot and manage services you can use the Services snap-in to the Microsoft Management Console. The MMC Services snap-in has feature for:

  • Monitoring the status of services.
  • Starting, stopping, pausing and resuming, or disabling services.
  • Viewing service properties and dependencies.
  • Setting up recovery actions to deal with service failures.

Leave a comment »


  1. Get size of json object

  var myObject = {'name':'Kasun', 'address':'columbo','age': '29'}

  var count = Object.keys(myObject).length;


2. Trying to pass in a boolean C# variable to a javascript variable and set it to true

myjavascript( <%= MyBooleanVariableInCSharp.ToString().ToLower() %> );

You may also want to try:

isFollowing: '@(Model.IsFollowing)' === '@true'

and an ever better way is to use:

isFollowing: @Json.Encode(Model.IsFollowing)

Leave a comment »

The following exception was thrown: Access to the path denied. Exception details: System.UnauthorizedAccessException: Access to the path

According to File.Delete Method…

An UnauthorizedAccessException means one of 4 things:

  1. The caller does not have the required permission.
  2. The file is an executable file that is in use.
  3. Path is a directory.
  4. Path specified a read-only file.

Other answers:

Try setting the access permissions to “Full control” for the .Net user from where you are reading/saving the files. You need to find out from the application pool for the website what is the identity it is running under (by default this is Application Pool Identity) and grant that the correct permissions.


Leave a comment »

Azure Scheduler 102 – Creating a Job

What is a Job Collection?

Simple Definition: Job Collection is a Collection of jobs that runs in a particular region.

A job collection contains a group of jobs, and maintains settings, quotas and throttles that are shared by jobs within the collection. A job collection is created by a subscription owner, and groups jobs together based on usage or application boundaries. It’s constrained to one region. It also allows the enforcement of quotas to constrain the usage of all jobs in that collection; the quotas include MaxJobs and MaxRecurrence.

What is a Job?

Simple Definition: a Task to be completed in a given time.

A job defines a single recurrent action, with simple or complex strategies for execution. Actions may include HTTP requests or storage queue requests.


How to create Scheduler Job?


Step 1: create a job collection

Note: this will create a standard job collection. If you need to change it to free plan (which allows only 5 jobs maximum) use the Scale configuration tab.


Step 2: Now you can choose the action type

  • Invoking a Web Service over HTTP/s


  • Post a message to a Windows Azure Storage Queue



 Selecting Action Type:

Invoking a Web Service over HTTP or HTTS will enable to choose http methods.


Post a message to a Windows Azure Storage Queue will enable inputs to enter storage and queue access details.


You can use existing Azure Resources as well.


Step 3: selecting schedule

You can run as a one time job by

  • Running it immediately by selecting “Now”


  • In a specific time


OR you can create a recurring job


The job status can be monitored via the portal

The queue message will be created in the queue in the specified schedule

Following is a job with a message viewed using storage explorer.


Creating a Scheduler may fail!

Creating the scheduler collection may fail if the queue name is not provided properly.

NOTE: “Queue name must be 3-63 characters in length may contain lower-case alphanumeric characters and dashes.”

< Back to Inroduciton


Leave a comment »

Azure Scheduler 101 – Introduction

Purpose: Run jobs on simple or complex recurring schedules

Windows Azure Scheduler allows you to invoke actions – such as calling HTTP/S endpoints or posting a message to a storage queue – on any schedule. With Scheduler, you create jobs in the cloud that reliably call services inside and outside of Windows Azure. You choose whether to run those jobs right away, on a recurring schedule, or at some point in the future.


Where can we use Scheduler?

  • SaaS apps can use Scheduler to invoke a web service that performs data management on a set schedule
  • Internal Uses (1st party):

    Process long running requests – Http/s requests will timeout when a response is not received within a certain amount of time. For complex requests, such as a series of SQL queries against a large database, posting a message to storage queues allows you to complete the work without building additional asynchronous logic into your web service.

    • Windows Azure Mobile Services powers its scheduled scripts feature with the Scheduler. Skype, XBOX Video also uses scheduler to schedule its tasks.
    • Another Windows Azure service uses the Scheduler to regularly invoke a web service that performs diagnostic log cleanup and data aggregation
  • Enable a service to be invoked when offline – Typically, a web service needs to be online at the time the Scheduler invokes the endpoint. With messages posted to storage queues, however, the service can be offline when the Scheduler sends the message and field the request when it later comes online.
  • Recurring application actions: As an example, a service may periodically get data from twitter and gather the data into a regular feed.
  • Daily maintenance: Web applications have needs such as daily pruning of logs, performing backups, and other maintenance tasks. An administrator may choose to backup the database at 1AM every day for the next 9 months, for example.


You will have a new section in the azure portal


If not, you can enable it using preview services


Portal Access High level view

Job collections: which lists available job collections which simple groups jobs.

Jobs: this section will show all the jobs which we can filter by job collection or status.


Next lets create a job > Next Post

Leave a comment »

Microsoft beats Amazon on Cloud Storage Prices

Microsoft has replaced Amazon to achieve the top performer position in the 2013 report of Nasuni Corporation.

“This year, our tests revealed that Microsoft Azure Blob Storage has taken a significant step ahead of last year’s leader, Amazon S3, to take the top spot. Across three primary tests (performance, scalability and stability), Microsoft emerged as a top performer in every category” – Nasuni 2013 Cloud Storage Report

The new prices will be applied from March 13th 2014.


Recent upgrades on azure storage layers has shown great improvements.



A pricing comparison:

Azure IaaS Disks are $0.095/GB-month with Geo Redundancy. With AWS in order to get high durability of VM disks, customers have to pay the price of both EBS Standard Volumes ($0.05/GB-month) and EBS Snapshot to S3 ($0.095/GB-month), which is 34% more expensive.

You can read the report HERE


You can watch the report HERE


Another study of Cloud SAYS

Though Amazon EC2 has the lowest price advantage over the other 4 providers at $0.12 per hour (now tied with Windows Azure), the lowest cost does not always mean the best value for a customer looking for maximizedperformance.Read More


To get Azure pricing HERE

Leave a comment »

Simplest way of compressing files using .net 4.5


We will try to create a sample project to demonstrate compression using .net 4.5

  1. Create a sample Console project
  2. Right click references > Add References

    Search and add the DLL “System.IO.Compression.FileSystem”


  3. Now let’s add a sample folder called “test” and add 2 sample text files in it.

  4. Now select the 2 sample test files and change the property “Copy to output directory” to “copy if newer”

    This will create the test folder and copy both the test files in to it in the debug folder which is the working folder for the program.


  5. Now you can use the following code in the Main program to compress the “test” folder


    Syntax (C#)

    public static void CreateFromDirectory(

        string sourceDirectoryName,

        string destinationArchiveFileName


    sourceDirectoryName: The path to the directory to be archived, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.

    destinationArchiveFileName: The path of the archive to be created, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.




    System.IO.Compression.ZipFile.CreateFromDirectory(“test”, “”);


    Output in Debug folder:


    Applying this in Windows Azure:

    Storing in the local file system won’t be applicable in azure environment. We need to store in a centralized location where all servers can access them.

    You can upload your files into a blob container and compress those files using a worker role & store them in another blob container.


    Moreover, there are plenty of other libraries that we use to compress. All has its pros and cons.


    Download Code Sample from HERE

Leave a comment » Web API 102 – Scaffolding

In the previous blog we discussed the Basics of Web API and try to understand the default code. Now we will try to create our custom Web API using a Case Study.

Case study:

We will build our own requirement.

  • We have a Public Product Catalog
  • Any organization or an individual can publish their products here
  • We will add more requirements when we move forward…

Step 1: Create a Model “Product”

(Note: I have put full namespaces so you can better understand where it came from.)

I have added some data annotations to the properties.

  • ID will be the Key property.
  • Name property is marked as required.
  • And the maximum length of the Description will be 500 characters.

Now let’s use Scaffolding to create the Controller using the Model “Product”.

Step 2: Select Scaffolding for Web API 2 with Entity Framework

Right Click Controller Folder à Add à Select “New Scaffolded Item”

Choose the following option in the Web API category:

Step 3: Populate Controller Details for Scaffolding

  • Give a Controller Name
  • You have the option to create Controllers with Asynchronous Controller Actions or without.
  • Select the Model Class “Product”
  • Create a New Data Context to work with Databases.

Error 1:

When scaffolding the controller from the Model following error may appear:

“There was an error generating ‘WebAPI1.Models.DBContext. Try rebuilding your project.”

Rebuilding the project would solve this error.

Error 2:

If the Product class doesn’t have a key property, when scaffolding following error may appear. Example: if ID property doesn’t have the Data Annotation Key.

Note: Make sure you rebuild the project after you add the Key property. Also rebuild after any changes in the Model, before Scaffolding.

Now you have Created the your custom API Controller “ProductController”.

In the next blog we will see the differences of Actions with and without Asynchronous behavior.

Leave a comment » Web API 101 – Basics

We will discuss some points and try to find “Why Web Api?”

  • Earlier we had following web services:

    • Soap services – supports only xml

    • WCF services – supports many data formats, Protocols: HTTP, TCP, UDP, and custom transports

      • For a comparison between SOAP & WCF: Here

      • For a comparison between WCF & Web Api: Here

  • Now apps are available in PCs, Mobiles, Tablets, Notebooks, electronic devices, etc. Not all these devices speak SOAP. But they do speak HTTP. When you have more clients, you need to scale. Web API tries to minimize unnecessary configurations and keeps it simple.
  • It is simply a framework that allows you to build HTTP services. Services that are activated by simple GET requests, or by passing plain XML over POST, and respond with non-SOAP content such as plain XML, a JSON string, or any other content that can be used by the consumer.
  • WCF was initially created to support SOAP + WS-* over a variety of transports. Not all platforms and devices support soap. There was need to non-SOAP services. WCF 3.5 added WebHttpBinding – a new binding to create non-SOAP service over HTTP, better known as a RESTful service. Although, WCF support increased over time, it came with some pain. So, the main goal of the Web APIs is to stop looking at HTTP through the eyes of WCF, and just use as a transport protocol to pass requests. Web API aims to properly use URIs, HTTP headers, and body to create HTTP services accessible by any devices and platforms available.

To Start a Web Api Project using Visual Studio 2013

  • Create a New ASP.NET Web Application

  • Select Web Api template

The project creates a sample Web API controller named “ValuesController”. It will be inherited from the ApiController class which defines properties and methods for API controller.

Since Web API is a http service, each controller will by default have HTTP METHODS.

  • GET
  • POST
  • PUT

Exercise 1:


This URL will call the default Method “Get”

    // GET api/values

        public IEnumerable<string> Get()


            return new string[] { “value1”“value2” };


This will return a string array. Example: we can use this to retrieve a product catalog.

Exercise 2:


This URL will call the default Method “Get”, now passing a parameter id.

        // GET api/values/5

        public string Get(int id)


            return “value”;


Example: we can use this to retrieve product by passing a product id.

Exercise 3: POST simple Json string using fiddler

We can use Fiddler, to send a POST requests.

FromBody attribute:

This forces Web API to read a simple type from the request body. However, only one argument in the action can be decorated with this attribute, and you get an exception when you try to decorate more than one. Without FromBody attribute it will return an error “HTTP/1.1 405 Method Not Allowed”. More

Exercise 4: POST Json Object using fiddler

Post Body = { “ProductName”=”Apple”, “Price”=”22”}

Exercise 5: POST Json Object as a Model using fiddler

Post Body = { “ProductName”=”Apple”, “Price”=”22”}

Exercise 6: POST Form data using fiddler

Change the content type

  • Content-type: application/x-www-form-urlencoded

Change Request body

  • Name=’Apple’&Price=’22’

Exercise 7: PUT (update) Json string using fiddler

Exercise 8: DELETE using fiddler

Note: body part is not applicable for DELETE.


Now, we have a basic idea about Web API, how to start a project, understanding existing sample code when a Web API project is created, and how to call HTTP methods of Api Controller.

In the Next Blog we will see how can we can work with custom methods on API Controller.


Leave a comment »