Archive for the ‘C#’ Category

Programmatic impersonation in C#

Thursday, November 27th, 2008

Impersonation

I recently deployed a WPF app on a server that allowed the user to stop and start some application-related services. The purpose of the app was to allow users with administrative rights an easy way to manage the services that they needed to manage. Granted, they could manage the services through the services MMC, but the little WPF app was a requirement, and it’s our job as developers to make things easier for our clients – right?

All went well until a change of requirements meant that a user without administrative rights needed to use the program to stop and start the required services. When I tried to use the app, I got an exception – quite rightly, stopping and starting the services required admin rights. We needed the restricted user to be able to log on and use the app, but still needed to restrict their permissions.

So – step in programmatic impersonation in C# – a way to give restricted users the power that that’s required, all within the confines of your application.

Gravatar Control Update

Tuesday, March 18th, 2008

The guys over at Gravatar.com have been hard at work updating their service, and I’ve updated the ASP.NET control I developed to reflect the changes.

Gravatar ASP.NET Control

Friday, February 22nd, 2008

I just got myself a freshclickmedia.com Gravatar over at gravatar.com. A Gravatar is a little avatar associated with an email address, and quite a few blogs use them to decorate post comments. Signing up is easy – all you need to do is supply an email address, and image, and give your image a content rating.

The source of the gravatar image tag points to gravatar.com’s image generator and includes an MD5 hash of the email address to prevent email harvesting. A ‘max rating’ parameter prevents the display of unsavoury content.

There are a wide number of blogging gravatar plugins, so I decided to write an ASP.NET custom control to do the job. Here I present the control and its features.

A quick tour of C# 3.0′s new language features

Wednesday, December 5th, 2007

With Visual Studio 2008 now fully released, I take a quick look at some of the new language features in C# 3.0.

Your first ASP.NET Custom Control

Sunday, December 2nd, 2007

One of the strengths of ASP.NET is the ability to write your own reusable custom controls, deploy them, and use them by simply dragging them onto a form from the toolbox. This tutorial walks through the implementation of a ‘TimePicker’ custom control.

C#’s null coalescing operator

Wednesday, November 14th, 2007

I’ve been programming in C# for about five years, and today whilst reading the C# language specification v3.0, came across the null coalescing operator. Much like T-SQL’s ISNULL function, the operator replaces null values with the specified replacement value.

Write your own Visual Studio .NET Snippets to improve your coding productivity

Wednesday, November 7th, 2007

Chances are that if you’ve been using Visual Studio .NET, you’ll have come across the concept of snippets – useful reusable chunks of code that are inserted after typing in a small textual identifier for that snippet. This tutorial describes Visual Studio .NET snippets and describes how you can create your own.