As I write this, there is a lot of unclear and contradictory information on how to do this. Here is the best way that I've found to do it. The steps below will add SimpleMembership to a WebForms project as well as enable you to use the WebSecurity class in code-behind, without any weirdness such as adding a .cshtml to your WebForms project (which will work but won't let you use WebSecurity anywhere but in that file)

  1. Create a brand-new ASP.NET WebForms project

  2. Open the Package Manager Console and run this command: install-package Microsoft.AspNet.WebPages.WebData

  3. Open web.config

    1. Add a connection string ...

I came across this inconvenient inconsistency while implementing a client-side CSV export from a filterable Kendo Grid. In short, when a DataSource is not filtered and/or sorted, the view() method returns an ObservableArray, which has a toJSON() method to convert its contents back to the raw data objects without the ObservableObject wrapper. However, when the DataSource is either filtered or sorted, the view() method returns a standard JavaScript Array of Kendo ObservableObjects. Each individual item in the array has a toJSON() method, but of course the array itself does not. When I asked Telerik support about this, they said that ...

How many times has this happened to you: you cut or copy a snippet of code, select where you want it to go, then whoops! you accidentally press ctrl-c instead of ctrl-v and copy a blank line or the selection you meant to replace. This is normally just a mild inconvenience requiring you to go back and copy the snippet again, but sometimes going back to that snippet isn't so easy. Maybe you carelessly cut the snippet and then closed the file so you can't undo it back, or maybe you copied from a remote location that you've been disconnected ...

Last time, I summarized Scott Guthrie's keynote session. This time, I'll summarize some of the following sessions.

Azure Websites - Things they don't teach the kids in school

This talk was actually not so much about Azure Websites as it was about the build system that Azure Websites uses to publish web projects from Git. The product is called "Project Kudu" and is an open-source project available on GitHub. The speaker demonstrated a number of  "power user" features of Kudu:

Streaming the application log to the console

This demo actually didn't work, but this could be immensely useful to assist ...

I recently had the pleasure of attending the global AzureConf 2013 event broadcast live on Microsoft's Channel 9. If you didn't get a chance to attend and don't want to spend the time to watch all of the sessions, I plan to summarize each of them over the next few posts. This is my summary of the keynote address.

Keynote

In the keynote, Scott Guthrie gave an overview of the current state of available Azure services, starting with the infrastructure itself. Windows Azure is flexible, supporting a variety of development languages and client platforms; open, with client SDK ...

I've worked on some reports lately that push one limit or another. Here are a few things that I've learned along the way:

Copy and pasting multiple report items

When a report has repeating groups of items that you must place by hand, it is natural to want to copy and paste all of the items at once. However, when you do this, you will usually be treated to a display suddenly filled with little yellow "warning" signs indicating that the pasted items now subtly overlap one another, even though their location and size might appear to be perfect when ...

This goal is common in DB upgrade scenarios, yet problematic to achieve without a major impact on the contents of the script.

The Problems

The most obvious approach is probably just to start a transaction, and after each statement, check @@error and roll back the transaction yourself. This approach means writing a lot of extra error-handling code. You could start a transaction with XACT_ABORT ON, and after each batch, check if there is still a transaction. If there isn't one, an error occurred. But now what? Many DDL statements require that they are the first statement in a batch, and ...

For the sake of example, imagine a database of books. Books can have a Publisher, but not all books have been published yet, so those books do not have a Publisher. In the database, this would be represented by a nullable FK column, and the EF model would include a navigation property called Publisher from Books to Publishers. Let's say you want to write a query over a data service that returns a list of book names and publisher names. A naive query would start off like this:
var query =
    from book in DataServiceReference.Context.Books
    select new {Title ...

As a C# developer, I have taken for granted the convenience of being able to navigate to a definition and then click the back button on my mouse to return to where I navigated from. When I started working on a VB.NET project in VS 2010, the mouse button no longer worked the same way. After searching the web, I was shocked to learn that this was a C# feature only, and that VB.NET, F#, and C++ do not support it! The good news is that there is an addin that can restore this functionality, but there is a catch, ...

If you’ve worked with ASP.NET membership and worked with the membership data directly in the database, you have probably run into this problem: there is a procedure called aspnet_Membership_CreateUser that sounds like you should be able to use it to create a user, but once you look at the parameter list, you quickly realize that this isn’t going to be as easy as you might have hoped, because the procedure requires you to pass in pre-hashed, pre-salted passwords. Now what? If your experience was anything like mine, you resigned yourself to using the .NET Membership classes, all the while wishing ...

Table-per-type (TPT) inheritance mapping in Entity Framework is one of two options for representing object hierarchies in a database, the other option being table-per-hierarchy (TPH). Out of the box, one is correct relational design with poor performance, and the other is, in neutral terms, denormalized design with good performance. In this article I will describe the differences between the two and demonstrate a way to fix the performance penalty of using the TPT mapping strategy.

TPT vs TPH Mapping

Why choose one over the other? There are other resources and articles out there that describe the differences in detail, but ...

Did you know that SQL Server has built-in support for base64 encoding and decoding and has since 2005? I sure didn’t, because it’s hidden in the depths of XQuery. Here is a complete sample showing a complete round trip from string to binary to base64, back to binary and back to string again.

declare @source varbinary(max), @encoded  varchar(max), @decoded varbinary(max)
set @source = convert(varbinary(max), 'Hello Base64')
set @encoded = cast('' as xml).value('xs:base64Binary(sql:variable("@source"))', 'varchar(max)')
set @decoded = cast('' as xml).value...

This technique might come in useful if you find yourself in a situation where you want to be able to execute untyped queries against the DB but don’t want to have to maintain two connection strings.

Parse the Provider Name and Connection String

Put this code into your partial ObjectContext class:

EntityConnectionStringBuilder _builder;
private EntityConnectionStringBuilder EntityConnStrBuilder
{
get
{
if (_builder == null)
{
_builder = new EntityConnectionStringBuilder(Connection.ConnectionString);
if (!String.IsNullOrWhiteSpace(_builder.Name))
_builder = new EntityConnectionStringBuilder(
ConfigurationManager.ConnectionStrings[_builder.Name].ConnectionString);
}
return _builder;
}
}

public string ProviderName
{
get { return EntityConnStrBuilder.Provider; }
}

public string ProviderConnectionString
{
get { return EntityConnStrBuilder.ProviderConnectionString; }...

In this article, I’m going to walk through the steps necessary to migrate a SQL Server 2008 DB to a server running SQL Server 2005 using only free tools or tools that come with SQL Server. The short description of the process is: Generate a script on SQL Server 2008, then run it on SQL Server 2005. However, there are a few potential pitfalls, and I’m going to show you what they are and how to circumvent them.

Generate Scripts on SQL Server 2008

Connect to the SQL Server 2008 server with Object Explorer. Locate the database and right-click on ...

In the past, I’ve always used MeasureUp as my practice certification exam provider. While I was never dissatisfied, I was also never completely satisfied either. For my most recent exam, I decided to change things up and try a different provider, and I chose the Kaplan tests from www.selftestsoftware.com. Now that I have used both, I have a few comparisons that I can share. To be clear, I won’t be comparing the MeasureUp practice exam to the same SelfTest practice exam. I will be comparing my past experience with MeasureUp, which consists of 6 prior exams, to my most ...

I used to wonder this myself, then came to my own conclusions about it and moved on. Recently, I was asked this question by another developer, and I thought that it might be worth writing about in case anyone else is wondering about it.

As engineers, one of our common impulses is to reduce redundancy and complexity by refactoring until nothing is duplicated. I think that’s where the initial impulse comes from when this question of consolidating lookups occurs to someone. They notice, “Hey, I have all these tables with a key and a value. They all have exactly the ...

When you’re trying to diagnose performance problems in SQL Server, what’s the first thing you usually do? For me, it’s usually running a trace in SQL Server Profiler for a while to see what’s happening and get an idea of the most expensive operations that are happening. This time, I decided to try something different and used the Dynamic Management Views instead. These views reflect the inner workings of SQL server, and querying them is like having the ability to query a very complete trace that is continuously running. I’m only just dipping my toes in these waters, but I’ve ...

You’ve probably heard it before: “Exceptions are expensive!” Maybe if you’re like me, you heard it but you didn’t believe it, not really. How bad could they be? Well, I was recently forced face-to-face with the reality of this saying, and I’m here to tell you, exceptions are expensive!

In my case, I was using a generic helper method that called Convert.ChangeType(). This method can throw, among other things, a FormatException if the input object is not in a format that can be converted to the requested type. Unfortunately, this particular class does not provide a way to check whether ...

I know, that title was a mouthful. Today I was posed with the challenge of writing a regular expression that would match an input that repeated the same word multiple times. Of course, it’s easy to write a regular expression that returns multiple matches of a single word, but it’s a little more challenging to write one that matches only once. Here is the sample input string we’re going to work with: “Just keep swimming. Just keep swimming. Just keep swimming, swimming, swimming.” The repeated word is “swimming”, and we only want to match inputs that repeat it 5 times ...

When working with regular expressions, you will quickly come across these terms. Matches are usually easy to understand, but Groups and Captures can be a bit trickier to understand. I’m going to explain them with a simple and concrete example. Let’s start with this regular expression pattern:

(?<AreaCode>\d{3})-(?<Triplet>\d{3})-(?<Quadruplet>\d{4})
 
We’ll run it against this text: 555-867-5309. We’ll get back one Match containing several Groups, each Group having one Capture. A Match represents one complete, successful match between the regular expression pattern and the input text. ...