When creating a new ASP.NET MVC 4 project in Visual Studio, the "Internet Application" template provides a jumpstart for using SimpleMembership and OAuth2 providers.  But you may quickly find that it some providers (Windows Live, Facebook, Twitter) require a redirect or source domain.  Most will not allow you to use a localhost address for this redirect domain which can make testing in a development environment difficult. (Note that OpenID providers, such as Google, do not require a redirect URL and these steps are not necessary to test from a localhost site.)

One solution is to come up with a unique ...

In my previous post,  I demonstrated how to implement a SQLite database in your Cordova mobile app using the SQLite plugin in Telerik's Icenium IDE.  Now we will see how to add barcode scanning to your app using the Barcode Scanner plugin.  Previously, we built a Shopping List app that lets you add items, mark them as complete, and clear completed items while storing all data in a local SQLite database.  Now we will add a new "Scan" feature so users can scan a barcode to add items to their list.

First, we need to add the Barcode ...

If you need relational storage for your Cordova-based app, SQLite provides a lightweight and feature-rich database.  I will walk you through the steps to use SQLite with Telerik's Icenium IDE and build a demo Shopping List app that will select, insert, update, and delete records from a local database on the device.

First, add the SQLite plugin in Icenium.  Double-click your "Properties" folder, select the Plugins tab and check the "SQLite" plugin.  This will add the Plugins folder and SQLite scripts within that folder.

Database and Table Setup

Before you can use your SQLite database and tables, you need to ...

Entity Framework makes it very easy to get data from your database through mapped entities and having foreign keys mapped as navigation properties makes it really easy to traverse relationships in your database.  However, there is often a lot of overhead if you "include" your entire child entity along with the primary, parent entity.

For example, let's say we have an Order entity and each Order has a non-null ShippingAddressId that gives us a 1..1 to the Address entity.  We can use Include() to return that related Address entity:

public void IQueryable<Order> GetOrders(
{
    return this.ObjectContext.Orders.Include("Address");...
Developing in XAML (Windows 8, Silverlight, Windows Phone, or WPF) gives you a powerful combination of declarative markup with databinding, but one shortcoming I often come up against is the ability to build simple ComboBox elements declaratively with both Content and Values.
If you are familiar with HTML, you know that you can use a select tag to pair the display name with a key value, such as:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value...
Using Ajax.BeginForm in your MVC View gives you an easy way of doing a partial postback via an AJAX call.  In its simplest form, our view would look something like this:

@model MyProject.Models.Person
 
<div id="myForm">
    @using (Ajax.BeginForm(new AjaxOptions())
    {
        <fieldset>
            <legend>This is a demo form.</legend>
            @Html.LabelFor(model => model.Name)
            @Html.TextBoxFor(model => model.Name)
 
            <input type="submit" value="Save" />
        </fieldset>
    }
</div>

The BeginForm method has several overloads which allow you to pass in ...
When building a full-featured MVC web site (or any web site), it is likely that you will have lots of JavaScript and CSS resources.  In addition, when you are using 3rd-party libraries, you can often get "minified" versions of the files, but you may end up with a handful or even dozens of separate js files.  It is important to reduce the load times of these files as much as possible.  There are a few concepts that help speed up page loads:
  1. Minify files: remove unnecessary spaces and line breaks so the file size is as small as possible.
  2. Combine ...
If you have used WCF RIA Services along with Entity Framework for Silverlight applications, you know how useful they are for performing database operations from your application.  With the WCF RIA Services Toolkit, it gives you even more flexibility to expose your RIA DomainService methods to not only a Silverlight application, but any application that can access a SOAP or JSON endpoint.
I will provide some steps here for setting up and consuming data through a SOAP endpoint.

1. Install WCF RIA Services Toolkit

You will need to install the toolkit in your development environment.  You can get it here...
I've enjoyed the chance to use Kendo UI over the last few weeks.  The UI Widgets are powerful and save a lot of development time.  And often when I find myself saying, "it would be great if I could. . ." it is already part of the product.

Many of the widgets make use of the DataSource component which has a built-in filter method.  This allows you to use operators such as "equal to" or "contains" to filter the data in your DataSource.  One of the less-documented capabilities of the DataSource filter is the ability to do custom filtering....
The ASP.NET MVC 4 Beta includes ASP.NET Web API which makes it very easy to expose data through a REST API in either XML or JSON with very little code.  There are some great tutorials on the asp.net site to get up and running.  After working with MVC 4 for a while, I have discovered a few quirks, so hopefully these tips will save you some time.

XML and IEnumerable Properties

The MVC4 ApiController will automatically detect the request's Content-Type to see if it is expecting application/json or text/xml in the response.  One of my model classes had a collection ...
log4net is a proven and simple means of enabling logging in your .NET application.  There are lots of resources available to walk you through the standard setup process, but I will give some steps for more advanced scenarios with multiple projects in a .NET solution.

One Config File, Multiple Projects

 In most circumstances, it is nice to be able to share a global log4net configuration file for all of the projects in your solution.  This way, you can make changes in one place and the next time you build, it will take effect for all logging in your project.

To ...
Mobile applications and web sites provide the perfect platform for proximity-based services so users can find the nearest X to their current location.  I will demonstrate some code that will allow you to find the closest location in a list when compared to a current latitude and longitude.

While latitude and longitude provide precise coordinates, we can't use a Euclidean distance formula because latitude and longitude are not on a cartesian plane, but on a sphere (technically, an ellipsoid, but we don't need to be so precise here).  There are several pages that describe the differences between using the Haversine ...

Silverlight provides a robust development environment and a rich user experience, but one shortcoming becomes evident when users ask "why can't I highlight and copy text in the application?"  Unlike standard web pages, when you use the Silverlight TextBlock, the text is inaccessible to the user and behaves almost like it is a background image.

There are several ways to remedy this, including building a custom control, but the simplest solution I've found is to use a TextBox control (which allows users to select and copy text) and style it to look like a TextBlock.  To do this, create a ...

There are some powerful data editing controls in Silverlight such as the DataForm which let you define templates for ReadOnly and Edit modes, but sometimes you just need a simple way to view and update text.  I came across a scenario in a custom application that required a simple way to view and edit text.  The solution I came up with was a "Click to Edit" TextBlock.  In the default state, the text is displayed as a read-only TextBlock, but you can simply click on the TextBlock for it to become an editable TextBox.

Here is a working example (Silverlight ...

It is quite easy to enable Out-of-Browser (OOB) mode when building a Silverlight application.  Open up the project properties on the Silverlight project and check the box to "Enable running application out of the browser."

The more difficult task is troubleshooting problems when the application works in browser, but not out of browser.  First, to debug OOB applications in Visual Studio, you need to open the Silverlight project properties and in the "Debug" tab, set the start action to "Out-of-browser application" and select the appropriate project from the dropdown list.  Next, set your Silverlight project as the startup project.  Now ...

When building Line-of-Business applications, we typically provide a variety of ways to search for customer or transaction data.  One of the common search types is a date range search.  Telerik provides an excellent UI control to select dates, the RadDatePicker.  

So now your application has a begin date and end date for your search and everything looks great until you realize that the end date is never included in the search results.  This is because the DatePicker control defaults to midnight on the selected day (0 hours, 0 minutes, 0 seconds, 0 milliseconds) and if you use less-than ...

Entity Framework can save you a lot of time when developing data operations in your application.  I am going to demonstrate some techniques to use calculated fields to filter or constrain your results in a LINQ to Entity query.

Before we get started, we’ll use a simple example of a Contact entity that has one or more Address entities associated with it:

public class Contact
{
	public int ContactId { get; set; }
	public string FirstName { get; set; }
	public string LastName { get; set; }
	public DateTime Birthday { get; set; }
	public List<Address> Addresses { get; set; }
}

public class Address
{
	public int ContactId { ...

By modifying the default ListBox and ListBoxItem styles and ControlTemplates, it isn’t too difficult to make ListBoxItems look the way you’d like.  You can also modify the existing MouseOver or Selected Storyboards to add your own animation effects.  But to add some additional polish to an application, I’ll demonstrate how to animate the adding and removing of ListBoxItems.

Here is a look at the finished example which allows you to add and remove ListBox items (Silverlight plug-in required):

Get Microsoft Silverlight

To start, we will animate the fade in and fade out of ListBoxItems as they are added and removed.

Use Expression Blend ...

The MVVM design pattern works extremely well in Silverlight.  A typical implementation of this pattern is to create a ViewModel for each View or Page in your application.  This gives you a clean separation between your View and ViewModel and it also provides logical separation for your ViewModels so they don’t get bloated.  For larger applications, you may find that each View has multiple ViewModels or a Page is comprised of several UserControls, each of which have their own ViewModel.  Once you get to this point, it can become challenging to communicate between the ViewModels and tie everything together in ...

While it seems like it should be a fairly straightforward task to set up application-wide themes in Silverlight, the ideal solution is a bit elusive. Most of the common solutions have their shortcomings:

  1. Use a separate ResourceDictionary for each theme and Add/Remove them from the Application.Resources.MergedDictionaries, but this is not very usable when you want the user to be able to switch themes with a click of the button. All of the controls that have Styles set need to go through the Measure/Arrange process to be styled correctly. This can be a challenge to do application-wide.
  2. Use the Silverlight Toolkit ...